home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / bash_114.zip / bash-1.14.2 / y.tab.c < prev    next >
C/C++ Source or Header  |  1994-08-10  |  117KB  |  4,095 lines

  1.  
  2. /*  A Bison parser, made from ./parse.y  */
  3.  
  4. #define YYBISON 1  /* Identify Bison output.  */
  5.  
  6. #define    IF    258
  7. #define    THEN    259
  8. #define    ELSE    260
  9. #define    ELIF    261
  10. #define    FI    262
  11. #define    CASE    263
  12. #define    ESAC    264
  13. #define    FOR    265
  14. #define    SELECT    266
  15. #define    WHILE    267
  16. #define    UNTIL    268
  17. #define    DO    269
  18. #define    DONE    270
  19. #define    FUNCTION    271
  20. #define    IN    272
  21. #define    BANG    273
  22. #define    WORD    274
  23. #define    ASSIGNMENT_WORD    275
  24. #define    NUMBER    276
  25. #define    AND_AND    277
  26. #define    OR_OR    278
  27. #define    GREATER_GREATER    279
  28. #define    LESS_LESS    280
  29. #define    LESS_AND    281
  30. #define    GREATER_AND    282
  31. #define    SEMI_SEMI    283
  32. #define    LESS_LESS_MINUS    284
  33. #define    AND_GREATER    285
  34. #define    LESS_GREATER    286
  35. #define    GREATER_BAR    287
  36. #define    yacc_EOF    288
  37.  
  38. #line 21 "./parse.y"
  39.  
  40. #include <stdio.h>
  41. #include "bashtypes.h"
  42. #include <signal.h>
  43. #include "bashansi.h"
  44. #include "shell.h"
  45. #include "flags.h"
  46. #include "input.h"
  47.  
  48. #if defined (READLINE)
  49. #  include <readline/readline.h>
  50. #endif /* READLINE */
  51.  
  52. #if defined (HISTORY)
  53. #  include "bashhist.h"
  54. #  include <readline/history.h>
  55. #endif /* HISTORY */
  56.  
  57. #if defined (JOB_CONTROL)
  58. #  include "jobs.h"
  59. #endif /* JOB_CONTROL */
  60.  
  61. #if defined (ALIAS)
  62. #  include "alias.h"
  63. #endif /* ALIAS */
  64.  
  65. #if defined (PROMPT_STRING_DECODE)
  66. #include <sys/param.h>
  67. #include <time.h>
  68. #include "maxpath.h"
  69. #endif /* PROMPT_STRING_DECODE */
  70.  
  71. #define YYDEBUG 1
  72. extern int eof_encountered;
  73. extern int no_line_editing;
  74. extern int current_command_number;
  75. extern int interactive, interactive_shell, login_shell;
  76. extern int posixly_correct;
  77. extern int last_command_exit_value;
  78. extern int interrupt_immediately;
  79. extern char *shell_name, *current_host_name;
  80. extern Function *last_shell_builtin, *this_shell_builtin;
  81. #if defined (READLINE)
  82. extern int bash_readline_initialized;
  83. #endif
  84. #if defined (BUFFERED_INPUT)
  85. extern int bash_input_fd_changed;
  86. #endif
  87.  
  88. /* **************************************************************** */
  89. /*                                    */
  90. /*            "Forward" declarations                */
  91. /*                                    */
  92. /* **************************************************************** */
  93.  
  94. /* This is kind of sickening.  In order to let these variables be seen by
  95.    all the functions that need them, I am forced to place their declarations
  96.    far away from the place where they should logically be found. */
  97.  
  98. static int reserved_word_acceptable ();
  99. static int read_token ();
  100.  
  101. static void report_syntax_error ();
  102. static void handle_eof_input_unit ();
  103. static void prompt_again ();
  104. static void reset_readline_prompt ();
  105. static void print_prompt ();
  106.  
  107. /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
  108. char *ps1_prompt, *ps2_prompt;
  109.  
  110. /* Handle on the current prompt string.  Indirectly points through
  111.    ps1_ or ps2_prompt. */
  112. char **prompt_string_pointer = (char **)NULL;
  113. char *current_prompt_string;
  114.  
  115. /* The decoded prompt string.  Used if READLINE is not defined or if
  116.    editing is turned off.  Analogous to current_readline_prompt. */
  117. static char *current_decoded_prompt;
  118.  
  119. /* The number of lines read from input while creating the current command. */
  120. int current_command_line_count = 0;
  121.  
  122. /* Variables to manage the task of reading here documents, because we need to
  123.    defer the reading until after a complete command has been collected. */
  124. static REDIRECT *redir_stack[10];
  125. int need_here_doc = 0;
  126.  
  127. /* Where shell input comes from.  History expansion is performed on each
  128.    line when the shell is interactive. */
  129. static char *shell_input_line = (char *)NULL;
  130. static int shell_input_line_index = 0;
  131. static int shell_input_line_size = 0;    /* Amount allocated for shell_input_line. */
  132. static int shell_input_line_len = 0;    /* strlen (shell_input_line) */
  133.  
  134. /* Either zero or EOF. */
  135. static int shell_input_line_terminator = 0;
  136.  
  137. static REDIRECTEE redir;
  138.  
  139. #line 122 "./parse.y"
  140. typedef union {
  141.   WORD_DESC *word;        /* the word that we read. */
  142.   int number;            /* the number that we read. */
  143.   WORD_LIST *word_list;
  144.   COMMAND *command;
  145.   REDIRECT *redirect;
  146.   ELEMENT element;
  147.   PATTERN_LIST *pattern;
  148. } YYSTYPE;
  149.  
  150. #ifndef YYLTYPE
  151. typedef
  152.   struct yyltype
  153.     {
  154.       int timestamp;
  155.       int first_line;
  156.       int first_column;
  157.       int last_line;
  158.       int last_column;
  159.       char *text;
  160.    }
  161.   yyltype;
  162.  
  163. #define YYLTYPE yyltype
  164. #endif
  165.  
  166. #include <stdio.h>
  167.  
  168. #ifndef __STDC__
  169. #define const
  170. #endif
  171.  
  172.  
  173.  
  174. #define    YYFINAL        258
  175. #define    YYFLAG        -32768
  176. #define    YYNTBASE    45
  177.  
  178. #define YYTRANSLATE(x) ((unsigned)(x) <= 288 ? yytranslate[x] : 73)
  179.  
  180. static const char yytranslate[] = {     0,
  181.      2,     2,     2,     2,     2,     2,     2,     2,     2,    35,
  182.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  183.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  184.      2,     2,     2,     2,     2,     2,     2,    33,     2,    43,
  185.     44,     2,     2,     2,    40,     2,     2,     2,     2,     2,
  186.      2,     2,     2,     2,     2,     2,     2,     2,    34,    39,
  187.      2,    38,     2,     2,     2,     2,     2,     2,     2,     2,
  188.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  189.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  190.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  191.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  192.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  193.      2,     2,    41,    37,    42,     2,     2,     2,     2,     2,
  194.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  195.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  196.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  197.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  198.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  199.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  200.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  201.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  202.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  203.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  204.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  205.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  206.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  207.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  208.     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
  209.     26,    27,    28,    29,    30,    31,    32,    36
  210. };
  211.  
  212. #if YYDEBUG != 0
  213. static const short yyprhs[] = {     0,
  214.      0,     3,     5,     8,    10,    11,    14,    17,    20,    24,
  215.     28,    31,    35,    38,    42,    45,    49,    52,    56,    59,
  216.     63,    66,    70,    73,    77,    80,    84,    87,    91,    94,
  217.     98,   101,   104,   108,   110,   112,   114,   116,   119,   121,
  218.    124,   126,   128,   130,   133,   140,   147,   155,   163,   174,
  219.    185,   192,   200,   207,   213,   219,   221,   223,   225,   227,
  220.    229,   236,   243,   251,   259,   270,   281,   287,   294,   301,
  221.    309,   314,   320,   324,   330,   338,   345,   349,   354,   361,
  222.    367,   369,   372,   377,   382,   388,   394,   396,   399,   405,
  223.    411,   418,   425,   427,   431,   434,   436,   440,   444,   448,
  224.    453,   458,   463,   468,   473,   475,   478,   480,   482,   484,
  225.    485,   488,   490,   493,   496,   501,   506,   510,   514,   516,
  226.    519,   524
  227. };
  228.  
  229. #endif
  230.  
  231. static const short yyrhs[] = {    70,
  232.     35,     0,    35,     0,     1,    35,     0,    36,     0,     0,
  233.     46,    19,     0,    38,    19,     0,    39,    19,     0,    21,
  234.     38,    19,     0,    21,    39,    19,     0,    24,    19,     0,
  235.     21,    24,    19,     0,    25,    19,     0,    21,    25,    19,
  236.      0,    26,    21,     0,    21,    26,    21,     0,    27,    21,
  237.      0,    21,    27,    21,     0,    26,    19,     0,    21,    26,
  238.     19,     0,    27,    19,     0,    21,    27,    19,     0,    29,
  239.     19,     0,    21,    29,    19,     0,    27,    40,     0,    21,
  240.     27,    40,     0,    26,    40,     0,    21,    26,    40,     0,
  241.     30,    19,     0,    21,    31,    19,     0,    31,    19,     0,
  242.     32,    19,     0,    21,    32,    19,     0,    19,     0,    20,
  243.      0,    47,     0,    47,     0,    49,    47,     0,    48,     0,
  244.     50,    48,     0,    50,     0,    52,     0,    53,     0,    53,
  245.     49,     0,    10,    19,    69,    14,    65,    15,     0,    10,
  246.     19,    69,    41,    65,    42,     0,    10,    19,    34,    69,
  247.     14,    65,    15,     0,    10,    19,    34,    69,    41,    65,
  248.     42,     0,    10,    19,    69,    17,    46,    68,    69,    14,
  249.     65,    15,     0,    10,    19,    69,    17,    46,    68,    69,
  250.     41,    65,    42,     0,     8,    19,    69,    17,    69,     9,
  251.      0,     8,    19,    69,    17,    62,    69,     9,     0,     8,
  252.     19,    69,    17,    60,     9,     0,    12,    65,    14,    65,
  253.     15,     0,    13,    65,    14,    65,    15,     0,    54,     0,
  254.     57,     0,    56,     0,    58,     0,    55,     0,    11,    19,
  255.     69,    14,    65,    15,     0,    11,    19,    69,    41,    65,
  256.     42,     0,    11,    19,    34,    69,    14,    65,    15,     0,
  257.     11,    19,    34,    69,    41,    65,    42,     0,    11,    19,
  258.     69,    17,    46,    68,    69,    14,    65,    15,     0,    11,
  259.     19,    69,    17,    46,    68,    69,    41,    65,    42,     0,
  260.     19,    43,    44,    69,    58,     0,    19,    43,    44,    69,
  261.     58,    49,     0,    16,    19,    43,    44,    69,    58,     0,
  262.     16,    19,    43,    44,    69,    58,    49,     0,    16,    19,
  263.     69,    58,     0,    16,    19,    69,    58,    49,     0,    43,
  264.     65,    44,     0,     3,    65,     4,    65,     7,     0,     3,
  265.     65,     4,    65,     5,    65,     7,     0,     3,    65,     4,
  266.     65,    59,     7,     0,    41,    65,    42,     0,     6,    65,
  267.      4,    65,     0,     6,    65,     4,    65,     5,    65,     0,
  268.      6,    65,     4,    65,    59,     0,    61,     0,    62,    61,
  269.      0,    69,    64,    44,    65,     0,    69,    64,    44,    69,
  270.      0,    69,    43,    64,    44,    65,     0,    69,    43,    64,
  271.     44,    69,     0,    63,     0,    62,    63,     0,    69,    64,
  272.     44,    65,    28,     0,    69,    64,    44,    69,    28,     0,
  273.     69,    43,    64,    44,    65,    28,     0,    69,    43,    64,
  274.     44,    69,    28,     0,    19,     0,    64,    37,    19,     0,
  275.     69,    66,     0,    67,     0,    67,    35,    69,     0,    67,
  276.     33,    69,     0,    67,    34,    69,     0,    67,    22,    69,
  277.     67,     0,    67,    23,    69,    67,     0,    67,    33,    69,
  278.     67,     0,    67,    34,    69,    67,     0,    67,    35,    69,
  279.     67,     0,    72,     0,    18,    72,     0,    35,     0,    34,
  280.      0,    36,     0,     0,    69,    35,     0,    71,     0,    71,
  281.     33,     0,    71,    34,     0,    71,    22,    69,    71,     0,
  282.     71,    23,    69,    71,     0,    71,    33,    71,     0,    71,
  283.     34,    71,     0,    72,     0,    18,    72,     0,    72,    37,
  284.     69,    72,     0,    51,     0
  285. };
  286.  
  287. #if YYDEBUG != 0
  288. static const short yyrline[] = { 0,
  289.    163,   172,   179,   195,   205,   207,   211,   216,   221,   226,
  290.    231,   236,   241,   247,   253,   258,   263,   268,   273,   278,
  291.    283,   288,   293,   300,   307,   312,   317,   322,   327,   332,
  292.    337,   353,   358,   365,   367,   369,   373,   377,   388,   390,
  293.    394,   396,   400,   402,   417,   419,   421,   423,   425,   427,
  294.    430,   432,   434,   436,   438,   440,   442,   444,   446,   448,
  295.    452,   458,   464,   470,   476,   482,   490,   493,   496,   499,
  296.    502,   505,   509,   513,   515,   517,   522,   526,   528,   530,
  297.    534,   535,   539,   541,   543,   545,   549,   550,   554,   556,
  298.    558,   560,   564,   566,   575,   583,   584,   585,   592,   596,
  299.    598,   600,   607,   609,   611,   613,   620,   621,   622,   625,
  300.    626,   635,   641,   650,   658,   660,   662,   669,   671,   673,
  301.    680,   683
  302. };
  303.  
  304. static const char * const yytname[] = {   "$","error","$illegal.","IF","THEN",
  305. "ELSE","ELIF","FI","CASE","ESAC","FOR","SELECT","WHILE","UNTIL","DO","DONE",
  306. "FUNCTION","IN","BANG","WORD","ASSIGNMENT_WORD","NUMBER","AND_AND","OR_OR","GREATER_GREATER",
  307. "LESS_LESS","LESS_AND","GREATER_AND","SEMI_SEMI","LESS_LESS_MINUS","AND_GREATER",
  308. "LESS_GREATER","GREATER_BAR","'&'","';'","'\\n'","yacc_EOF","'|'","'>'","'<'",
  309. "'-'","'{'","'}'","'('","')'","inputunit","words","redirection","simple_command_element",
  310. "redirections","simple_command","command","shell_command","shell_command_1",
  311. "select_command","function_def","subshell","if_command","group_command","elif_clause",
  312. "case_clause_1","pattern_list_1","case_clause_sequence","pattern_list","pattern",
  313. "list","list0","list1","list_terminator","newlines","simple_list","simple_list1",
  314. "pipeline",""
  315. };
  316. #endif
  317.  
  318. static const short yyr1[] = {     0,
  319.     45,    45,    45,    45,    46,    46,    47,    47,    47,    47,
  320.     47,    47,    47,    47,    47,    47,    47,    47,    47,    47,
  321.     47,    47,    47,    47,    47,    47,    47,    47,    47,    47,
  322.     47,    47,    47,    48,    48,    48,    49,    49,    50,    50,
  323.     51,    51,    52,    52,    53,    53,    53,    53,    53,    53,
  324.     53,    53,    53,    53,    53,    53,    53,    53,    53,    53,
  325.     54,    54,    54,    54,    54,    54,    55,    55,    55,    55,
  326.     55,    55,    56,    57,    57,    57,    58,    59,    59,    59,
  327.     60,    60,    61,    61,    61,    61,    62,    62,    63,    63,
  328.     63,    63,    64,    64,    65,    66,    66,    66,    66,    67,
  329.     67,    67,    67,    67,    67,    67,    68,    68,    68,    69,
  330.     69,    70,    70,    70,    71,    71,    71,    71,    71,    71,
  331.     72,    72
  332. };
  333.  
  334. static const short yyr2[] = {     0,
  335.      2,     1,     2,     1,     0,     2,     2,     2,     3,     3,
  336.      2,     3,     2,     3,     2,     3,     2,     3,     2,     3,
  337.      2,     3,     2,     3,     2,     3,     2,     3,     2,     3,
  338.      2,     2,     3,     1,     1,     1,     1,     2,     1,     2,
  339.      1,     1,     1,     2,     6,     6,     7,     7,    10,    10,
  340.      6,     7,     6,     5,     5,     1,     1,     1,     1,     1,
  341.      6,     6,     7,     7,    10,    10,     5,     6,     6,     7,
  342.      4,     5,     3,     5,     7,     6,     3,     4,     6,     5,
  343.      1,     2,     4,     4,     5,     5,     1,     2,     5,     5,
  344.      6,     6,     1,     3,     2,     1,     3,     3,     3,     4,
  345.      4,     4,     4,     4,     1,     2,     1,     1,     1,     0,
  346.      2,     1,     2,     2,     4,     4,     3,     3,     1,     2,
  347.      4,     1
  348. };
  349.  
  350. static const short yydefact[] = {     0,
  351.      0,   110,     0,     0,     0,   110,   110,     0,     0,    34,
  352.     35,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  353.      2,     4,     0,     0,   110,   110,    36,    39,    41,   122,
  354.     42,    43,    56,    60,    58,    57,    59,     0,   112,   119,
  355.      3,     0,     0,   110,   110,   110,     0,     0,   110,   120,
  356.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  357.     11,    13,    19,    15,    27,    21,    17,    25,    23,    29,
  358.     31,    32,     7,     8,     0,     0,    34,    40,    37,    44,
  359.      1,   110,   110,   113,   114,   110,   110,     0,   111,    95,
  360.     96,   105,     0,   110,     0,   110,     0,   110,   110,     0,
  361.      0,   110,    12,    14,    20,    16,    28,    22,    18,    26,
  362.     24,    30,    33,     9,    10,    77,    73,    38,     0,     0,
  363.    117,   118,     0,     0,   106,   110,   110,   110,   110,   110,
  364.    110,     0,   110,     5,   110,     0,   110,     5,   110,     0,
  365.      0,   110,    71,     0,   115,   116,     0,     0,   121,   110,
  366.    110,    74,     0,     0,     0,    98,    99,    97,     0,    81,
  367.    110,    87,     0,   110,   110,     0,     0,     0,   110,   110,
  368.      0,     0,     0,    54,    55,     0,    72,    67,     0,     0,
  369.     76,   100,   101,   102,   103,   104,    53,    82,    88,     0,
  370.     51,    93,     0,     0,     0,     0,    45,     6,   108,   107,
  371.    109,   110,    46,     0,     0,    61,   110,    62,    69,    68,
  372.     75,   110,   110,   110,   110,    52,     0,     0,   110,    47,
  373.     48,     0,    63,    64,     0,    70,    78,     0,     0,     0,
  374.    110,    94,    83,    84,   110,   110,   110,   110,   110,    80,
  375.     85,    86,    89,    90,     0,     0,     0,     0,    79,    91,
  376.     92,    49,    50,    65,    66,     0,     0,     0
  377. };
  378.  
  379. static const short yydefgoto[] = {   256,
  380.    167,    27,    28,    80,    29,    30,    31,    32,    33,    34,
  381.     35,    36,    37,   153,   159,   160,   161,   162,   194,    42,
  382.     90,    91,   202,    43,    38,   121,    92
  383. };
  384.  
  385. static const short yypact[] = {   233,
  386.    -28,-32768,     2,    10,    15,-32768,-32768,    32,   437,    19,
  387. -32768,   494,    46,    52,    -5,    39,    59,    61,    93,    95,
  388. -32768,-32768,   102,   103,-32768,-32768,-32768,-32768,   462,-32768,
  389. -32768,   478,-32768,-32768,-32768,-32768,-32768,    71,   116,    91,
  390. -32768,   126,   301,-32768,   117,   118,   123,   139,    89,    91,
  391.    111,   137,   138,    75,    76,   141,   143,   146,   148,   149,
  392. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
  393. -32768,-32768,-32768,-32768,   127,   131,-32768,-32768,-32768,   478,
  394. -32768,-32768,-32768,   369,   369,-32768,-32768,   437,-32768,-32768,
  395.    101,    91,    37,-32768,    -4,-32768,    22,-32768,-32768,   133,
  396.    -23,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
  397. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,   335,   335,
  398.     60,    60,   403,    98,    91,-32768,-32768,-32768,-32768,-32768,
  399. -32768,     3,-32768,-32768,-32768,    33,-32768,-32768,-32768,   167,
  400.    172,-32768,   478,   -23,-32768,-32768,   369,   369,    91,-32768,
  401. -32768,-32768,   181,   301,   301,   301,   301,   301,   186,-32768,
  402. -32768,-32768,    21,-32768,-32768,   192,    83,   168,-32768,-32768,
  403.    194,    83,   175,-32768,-32768,   -23,   478,   478,   208,   214,
  404. -32768,-32768,-32768,    87,    87,    87,-32768,-32768,-32768,    24,
  405. -32768,-32768,   200,   -22,   205,   179,-32768,-32768,-32768,-32768,
  406. -32768,-32768,-32768,   207,   182,-32768,-32768,-32768,   478,   478,
  407. -32768,-32768,-32768,-32768,-32768,-32768,    29,   204,-32768,-32768,
  408. -32768,    34,-32768,-32768,    35,   478,   135,   301,   301,   301,
  409. -32768,-32768,   198,   173,-32768,-32768,-32768,-32768,-32768,-32768,
  410.    199,   267,-32768,-32768,   213,   193,   222,   196,-32768,-32768,
  411. -32768,-32768,-32768,-32768,-32768,   239,   240,-32768
  412. };
  413.  
  414. static const short yypgoto[] = {-32768,
  415.    104,   -30,   218,  -132,-32768,-32768,-32768,-32768,-32768,-32768,
  416. -32768,-32768,   -92,    28,-32768,   100,-32768,   105,    55,    -6,
  417. -32768,  -130,    78,   -41,-32768,     6,    23
  418. };
  419.  
  420.  
  421. #define    YYLAST        533
  422.  
  423.  
  424. static const short yytable[] = {    47,
  425.     48,    79,    93,    95,    97,    39,    41,   101,   143,   133,
  426.    177,    89,   134,    63,   218,    64,   164,    25,    75,    76,
  427.     44,   219,    40,   182,   183,   184,   185,   186,    45,   191,
  428.     89,    50,   216,    46,    65,   137,   135,    89,   138,   192,
  429.    119,   120,   192,   165,   123,   210,   169,   235,   237,   118,
  430.     49,   178,   132,   131,   136,    89,    89,    66,    89,    67,
  431.    144,    51,   139,   193,    61,   218,   193,    89,    89,    89,
  432.     62,    89,   231,   170,   236,   238,   226,    69,    68,    70,
  433.    124,    82,    83,   209,   154,   155,   156,   157,   158,   163,
  434.    122,   140,   141,   105,   108,   106,   109,   184,   185,   186,
  435.    176,   198,   150,   151,   152,    81,    40,    40,   126,   127,
  436.    125,    71,    79,    72,   107,   110,   199,   200,   201,   190,
  437.     73,    74,   126,   127,   145,   146,   166,    86,   168,    87,
  438.    171,   100,   173,   128,   129,   130,    98,    82,    83,   239,
  439.    151,    40,    40,   179,   180,   149,   118,    79,    84,    85,
  440.     94,    96,    99,   122,   102,   103,   104,   195,   196,   111,
  441.    222,   112,   204,   205,   113,   225,   114,   115,   116,    40,
  442.     40,   228,   229,   230,   117,     2,   142,   234,    79,   118,
  443.      3,   174,     4,     5,     6,     7,   175,   181,     8,   242,
  444.     88,    10,    11,    12,   187,   118,    13,    14,    15,    16,
  445.    244,    17,    18,    19,    20,   227,   197,    89,   206,   203,
  446.     23,    24,   233,    25,   211,    26,   208,   212,   192,   220,
  447.    221,   223,   232,   224,   241,   243,   250,   252,   245,   246,
  448.    247,   248,   249,     1,   253,     2,   254,   255,   257,   258,
  449.      3,   172,     4,     5,     6,     7,    78,   217,     8,   207,
  450.      9,    10,    11,    12,   240,     0,    13,    14,    15,    16,
  451.    188,    17,    18,    19,    20,   189,     0,    21,    22,     2,
  452.     23,    24,     0,    25,     3,    26,     4,     5,     6,     7,
  453.      0,     0,     8,     0,    88,    10,    11,    12,     0,     0,
  454.     13,    14,    15,    16,   251,    17,    18,    19,    20,     0,
  455.      0,    89,     0,     2,    23,    24,     0,    25,     3,    26,
  456.      4,     5,     6,     7,     0,     0,     8,     0,    88,    10,
  457.     11,    12,     0,     0,    13,    14,    15,    16,     0,    17,
  458.     18,    19,    20,     0,     0,    89,     0,     2,    23,    24,
  459.      0,    25,     3,    26,     4,     5,     6,     7,     0,     0,
  460.      8,     0,     9,    10,    11,    12,     0,     0,    13,    14,
  461.     15,    16,     0,    17,    18,    19,    20,     0,     0,    89,
  462.      0,     2,    23,    24,     0,    25,     3,    26,     4,     5,
  463.      6,     7,     0,     0,     8,     0,     9,    10,    11,    12,
  464.      0,     0,    13,    14,    15,    16,     0,    17,    18,    19,
  465.     20,     0,     0,     0,     0,     2,    23,    24,     0,    25,
  466.      3,    26,     4,     5,     6,     7,     0,     0,     8,     0,
  467.      0,    10,    11,    12,     0,     0,    13,    14,    15,    16,
  468.      0,    17,    18,    19,    20,     0,     0,    89,     0,     2,
  469.     23,    24,     0,    25,     3,    26,     4,     5,     6,     7,
  470.      0,     0,     8,     0,     0,    10,    11,    12,     0,     0,
  471.     13,    14,    15,    16,     0,    17,    18,    19,    20,     0,
  472.      0,     0,     0,     0,    23,    24,     0,    25,     0,    26,
  473.     77,    11,    12,     0,     0,    13,    14,    15,    16,     0,
  474.     17,    18,    19,    20,     0,     0,     0,     0,    12,    23,
  475.     24,    13,    14,    15,    16,     0,    17,    18,    19,    20,
  476.      0,     0,     0,     0,     0,    23,    24,    52,    53,    54,
  477.     55,     0,    56,     0,    57,    58,     0,     0,     0,     0,
  478.      0,    59,    60
  479. };
  480.  
  481. static const short yycheck[] = {     6,
  482.      7,    32,    44,    45,    46,     0,    35,    49,   101,    14,
  483.    143,    35,    17,    19,    37,    21,    14,    41,    25,    26,
  484.     19,    44,     0,   154,   155,   156,   157,   158,    19,     9,
  485.     35,     9,     9,    19,    40,    14,    41,    35,    17,    19,
  486.     82,    83,    19,    41,    86,   178,    14,    14,    14,    80,
  487.     19,   144,    94,    17,    96,    35,    35,    19,    35,    21,
  488.    102,    43,    41,    43,    19,    37,    43,    35,    35,    35,
  489.     19,    35,    44,    41,    41,    41,   209,    19,    40,    19,
  490.     87,    22,    23,   176,   126,   127,   128,   129,   130,   131,
  491.     85,    98,    99,    19,    19,    21,    21,   228,   229,   230,
  492.    142,    19,     5,     6,     7,    35,    84,    85,    22,    23,
  493.     88,    19,   143,    19,    40,    40,    34,    35,    36,   161,
  494.     19,    19,    22,    23,   119,   120,   133,    37,   135,     4,
  495.    137,    43,   139,    33,    34,    35,    14,    22,    23,     5,
  496.      6,   119,   120,   150,   151,   123,   177,   178,    33,    34,
  497.     34,    34,    14,   148,    44,    19,    19,   164,   165,    19,
  498.    202,    19,   169,   170,    19,   207,    19,    19,    42,   147,
  499.    148,   213,   214,   215,    44,     3,    44,   219,   209,   210,
  500.      8,    15,    10,    11,    12,    13,    15,     7,    16,   231,
  501.     18,    19,    20,    21,     9,   226,    24,    25,    26,    27,
  502.     28,    29,    30,    31,    32,   212,    15,    35,    15,    42,
  503.     38,    39,   219,    41,     7,    43,    42,     4,    19,    15,
  504.     42,    15,    19,    42,   231,    28,    28,    15,   235,   236,
  505.    237,   238,   239,     1,    42,     3,    15,    42,     0,     0,
  506.      8,   138,    10,    11,    12,    13,    29,   193,    16,   172,
  507.     18,    19,    20,    21,   227,    -1,    24,    25,    26,    27,
  508.    161,    29,    30,    31,    32,   161,    -1,    35,    36,     3,
  509.     38,    39,    -1,    41,     8,    43,    10,    11,    12,    13,
  510.     -1,    -1,    16,    -1,    18,    19,    20,    21,    -1,    -1,
  511.     24,    25,    26,    27,    28,    29,    30,    31,    32,    -1,
  512.     -1,    35,    -1,     3,    38,    39,    -1,    41,     8,    43,
  513.     10,    11,    12,    13,    -1,    -1,    16,    -1,    18,    19,
  514.     20,    21,    -1,    -1,    24,    25,    26,    27,    -1,    29,
  515.     30,    31,    32,    -1,    -1,    35,    -1,     3,    38,    39,
  516.     -1,    41,     8,    43,    10,    11,    12,    13,    -1,    -1,
  517.     16,    -1,    18,    19,    20,    21,    -1,    -1,    24,    25,
  518.     26,    27,    -1,    29,    30,    31,    32,    -1,    -1,    35,
  519.     -1,     3,    38,    39,    -1,    41,     8,    43,    10,    11,
  520.     12,    13,    -1,    -1,    16,    -1,    18,    19,    20,    21,
  521.     -1,    -1,    24,    25,    26,    27,    -1,    29,    30,    31,
  522.     32,    -1,    -1,    -1,    -1,     3,    38,    39,    -1,    41,
  523.      8,    43,    10,    11,    12,    13,    -1,    -1,    16,    -1,
  524.     -1,    19,    20,    21,    -1,    -1,    24,    25,    26,    27,
  525.     -1,    29,    30,    31,    32,    -1,    -1,    35,    -1,     3,
  526.     38,    39,    -1,    41,     8,    43,    10,    11,    12,    13,
  527.     -1,    -1,    16,    -1,    -1,    19,    20,    21,    -1,    -1,
  528.     24,    25,    26,    27,    -1,    29,    30,    31,    32,    -1,
  529.     -1,    -1,    -1,    -1,    38,    39,    -1,    41,    -1,    43,
  530.     19,    20,    21,    -1,    -1,    24,    25,    26,    27,    -1,
  531.     29,    30,    31,    32,    -1,    -1,    -1,    -1,    21,    38,
  532.     39,    24,    25,    26,    27,    -1,    29,    30,    31,    32,
  533.     -1,    -1,    -1,    -1,    -1,    38,    39,    24,    25,    26,
  534.     27,    -1,    29,    -1,    31,    32,    -1,    -1,    -1,    -1,
  535.     -1,    38,    39
  536. };
  537. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  538. #line 3 "/usr/local/lib/bison.simple"
  539.  
  540. /* Skeleton output parser for bison,
  541.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  542.  
  543.    This program is free software; you can redistribute it and/or modify
  544.    it under the terms of the GNU General Public License as published by
  545.    the Free Software Foundation; either version 1, or (at your option)
  546.    any later version.
  547.  
  548.    This program is distributed in the hope that it will be useful,
  549.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  550.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  551.    GNU General Public License for more details.
  552.  
  553.    You should have received a copy of the GNU General Public License
  554.    along with this program; if not, write to the Free Software
  555.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  556.  
  557.  
  558. #ifndef alloca
  559. #ifdef __GNUC__
  560. #define alloca __builtin_alloca
  561. #else /* not GNU C.  */
  562. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  563. #include <alloca.h>
  564. #else /* not sparc */
  565. #if defined (MSDOS) && !defined (__TURBOC__)
  566. #include <malloc.h>
  567. #else /* not MSDOS, or __TURBOC__ */
  568. #if defined(_AIX)
  569. #include <malloc.h>
  570.  #pragma alloca
  571. #endif /* not _AIX */
  572. #endif /* not MSDOS, or __TURBOC__ */
  573. #endif /* not sparc.  */
  574. #endif /* not GNU C.  */
  575. #endif /* alloca not defined.  */
  576.  
  577. /* This is the parser code that is written into each bison parser
  578.   when the %semantic_parser declaration is not specified in the grammar.
  579.   It was written by Richard Stallman by simplifying the hairy parser
  580.   used when %semantic_parser is specified.  */
  581.  
  582. /* Note: there must be only one dollar sign in this file.
  583.    It is replaced by the list of actions, each action
  584.    as one case of the switch.  */
  585.  
  586. #define yyerrok        (yyerrstatus = 0)
  587. #define yyclearin    (yychar = YYEMPTY)
  588. #define YYEMPTY        -2
  589. #define YYEOF        0
  590. #define YYACCEPT    return(0)
  591. #define YYABORT     return(1)
  592. #define YYERROR        goto yyerrlab1
  593. /* Like YYERROR except do call yyerror.
  594.    This remains here temporarily to ease the
  595.    transition to the new meaning of YYERROR, for GCC.
  596.    Once GCC version 2 has supplanted version 1, this can go.  */
  597. #define YYFAIL        goto yyerrlab
  598. #define YYRECOVERING()  (!!yyerrstatus)
  599. #define YYBACKUP(token, value) \
  600. do                                \
  601.   if (yychar == YYEMPTY && yylen == 1)                \
  602.     { yychar = (token), yylval = (value);            \
  603.       yychar1 = YYTRANSLATE (yychar);                \
  604.       YYPOPSTACK;                        \
  605.       goto yybackup;                        \
  606.     }                                \
  607.   else                                \
  608.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  609. while (0)
  610.  
  611. #define YYTERROR    1
  612. #define YYERRCODE    256
  613.  
  614. #ifndef YYPURE
  615. #define YYLEX        yylex()
  616. #endif
  617.  
  618. #ifdef YYPURE
  619. #ifdef YYLSP_NEEDED
  620. #define YYLEX        yylex(&yylval, &yylloc)
  621. #else
  622. #define YYLEX        yylex(&yylval)
  623. #endif
  624. #endif
  625.  
  626. /* If nonreentrant, generate the variables here */
  627.  
  628. #ifndef YYPURE
  629.  
  630. int    yychar;            /*  the lookahead symbol        */
  631. YYSTYPE    yylval;            /*  the semantic value of the        */
  632.                 /*  lookahead symbol            */
  633.  
  634. #ifdef YYLSP_NEEDED
  635. YYLTYPE yylloc;            /*  location data for the lookahead    */
  636.                 /*  symbol                */
  637. #endif
  638.  
  639. int yynerrs;            /*  number of parse errors so far       */
  640. #endif  /* not YYPURE */
  641.  
  642. #if YYDEBUG != 0
  643. int yydebug;            /*  nonzero means print parse trace    */
  644. /* Since this is uninitialized, it does not stop multiple parsers
  645.    from coexisting.  */
  646. #endif
  647.  
  648. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  649.  
  650. #ifndef    YYINITDEPTH
  651. #define YYINITDEPTH 200
  652. #endif
  653.  
  654. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  655.     (effective only if the built-in stack extension method is used).  */
  656.  
  657. #if YYMAXDEPTH == 0
  658. #undef YYMAXDEPTH
  659. #endif
  660.  
  661. #ifndef YYMAXDEPTH
  662. #define YYMAXDEPTH 10000
  663. #endif
  664.  
  665. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  666. #define __yy_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  667. #else                /* not GNU C or C++ */
  668. #ifndef __cplusplus
  669.  
  670. /* This is the most reliable way to avoid incompatibilities
  671.    in available built-in functions on various systems.  */
  672. static void
  673. __yy_bcopy (from, to, count)
  674.      char *from;
  675.      char *to;
  676.      int count;
  677. {
  678.   register char *f = from;
  679.   register char *t = to;
  680.   register int i = count;
  681.  
  682.   while (i-- > 0)
  683.     *t++ = *f++;
  684. }
  685.  
  686. #else /* __cplusplus */
  687.  
  688. /* This is the most reliable way to avoid incompatibilities
  689.    in available built-in functions on various systems.  */
  690. static void
  691. __yy_bcopy (char *from, char *to, int count)
  692. {
  693.   register char *f = from;
  694.   register char *t = to;
  695.   register int i = count;
  696.  
  697.   while (i-- > 0)
  698.     *t++ = *f++;
  699. }
  700.  
  701. #endif
  702. #endif
  703.  
  704. #line 169 "/usr/local/lib/bison.simple"
  705. int
  706. yyparse()
  707. {
  708.   register int yystate;
  709.   register int yyn;
  710.   register short *yyssp;
  711.   register YYSTYPE *yyvsp;
  712.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  713.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  714.  
  715.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  716.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  717.  
  718.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  719.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  720.  
  721. #ifdef YYLSP_NEEDED
  722.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  723.   YYLTYPE *yyls = yylsa;
  724.   YYLTYPE *yylsp;
  725.  
  726. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  727. #else
  728. #define YYPOPSTACK   (yyvsp--, yyssp--)
  729. #endif
  730.  
  731.   int yystacksize = YYINITDEPTH;
  732.  
  733. #ifdef YYPURE
  734.   int yychar;
  735.   YYSTYPE yylval;
  736.   int yynerrs;
  737. #ifdef YYLSP_NEEDED
  738.   YYLTYPE yylloc;
  739. #endif
  740. #endif
  741.  
  742.   YYSTYPE yyval;        /*  the variable used to return        */
  743.                 /*  semantic values from the action    */
  744.                 /*  routines                */
  745.  
  746.   int yylen;
  747.  
  748. #if YYDEBUG != 0
  749.   if (yydebug)
  750.     fprintf(stderr, "Starting parse\n");
  751. #endif
  752.  
  753.   yystate = 0;
  754.   yyerrstatus = 0;
  755.   yynerrs = 0;
  756.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  757.  
  758.   /* Initialize stack pointers.
  759.      Waste one element of value and location stack
  760.      so that they stay on the same level as the state stack.  */
  761.  
  762.   yyssp = yyss - 1;
  763.   yyvsp = yyvs;
  764. #ifdef YYLSP_NEEDED
  765.   yylsp = yyls;
  766. #endif
  767.  
  768. /* Push a new state, which is found in  yystate  .  */
  769. /* In all cases, when you get here, the value and location stacks
  770.    have just been pushed. so pushing a state here evens the stacks.  */
  771. yynewstate:
  772.  
  773.   *++yyssp = yystate;
  774.  
  775.   if (yyssp >= yyss + yystacksize - 1)
  776.     {
  777.       /* Give user a chance to reallocate the stack */
  778.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  779.       YYSTYPE *yyvs1 = yyvs;
  780.       short *yyss1 = yyss;
  781. #ifdef YYLSP_NEEDED
  782.       YYLTYPE *yyls1 = yyls;
  783. #endif
  784.  
  785.       /* Get the current used size of the three stacks, in elements.  */
  786.       int size = yyssp - yyss + 1;
  787.  
  788. #ifdef yyoverflow
  789.       /* Each stack pointer address is followed by the size of
  790.      the data in use in that stack, in bytes.  */
  791.       yyoverflow("parser stack overflow",
  792.          &yyss1, size * sizeof (*yyssp),
  793.          &yyvs1, size * sizeof (*yyvsp),
  794. #ifdef YYLSP_NEEDED
  795.          &yyls1, size * sizeof (*yylsp),
  796. #endif
  797.          &yystacksize);
  798.  
  799.       yyss = yyss1; yyvs = yyvs1;
  800. #ifdef YYLSP_NEEDED
  801.       yyls = yyls1;
  802. #endif
  803. #else /* no yyoverflow */
  804.       /* Extend the stack our own way.  */
  805.       if (yystacksize >= YYMAXDEPTH)
  806.     {
  807.       yyerror("parser stack overflow");
  808.       return 2;
  809.     }
  810.       yystacksize *= 2;
  811.       if (yystacksize > YYMAXDEPTH)
  812.     yystacksize = YYMAXDEPTH;
  813.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  814.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  815.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  816.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  817. #ifdef YYLSP_NEEDED
  818.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  819.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  820. #endif
  821. #endif /* no yyoverflow */
  822.  
  823.       yyssp = yyss + size - 1;
  824.       yyvsp = yyvs + size - 1;
  825. #ifdef YYLSP_NEEDED
  826.       yylsp = yyls + size - 1;
  827. #endif
  828.  
  829. #if YYDEBUG != 0
  830.       if (yydebug)
  831.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  832. #endif
  833.  
  834.       if (yyssp >= yyss + yystacksize - 1)
  835.     YYABORT;
  836.     }
  837.  
  838. #if YYDEBUG != 0
  839.   if (yydebug)
  840.     fprintf(stderr, "Entering state %d\n", yystate);
  841. #endif
  842.  
  843.  yybackup:
  844.  
  845. /* Do appropriate processing given the current state.  */
  846. /* Read a lookahead token if we need one and don't already have one.  */
  847. /* yyresume: */
  848.  
  849.   /* First try to decide what to do without reference to lookahead token.  */
  850.  
  851.   yyn = yypact[yystate];
  852.   if (yyn == YYFLAG)
  853.     goto yydefault;
  854.  
  855.   /* Not known => get a lookahead token if don't already have one.  */
  856.  
  857.   /* yychar is either YYEMPTY or YYEOF
  858.      or a valid token in external form.  */
  859.  
  860.   if (yychar == YYEMPTY)
  861.     {
  862. #if YYDEBUG != 0
  863.       if (yydebug)
  864.     fprintf(stderr, "Reading a token: ");
  865. #endif
  866.       yychar = YYLEX;
  867.     }
  868.  
  869.   /* Convert token to internal form (in yychar1) for indexing tables with */
  870.  
  871.   if (yychar <= 0)        /* This means end of input. */
  872.     {
  873.       yychar1 = 0;
  874.       yychar = YYEOF;        /* Don't call YYLEX any more */
  875.  
  876. #if YYDEBUG != 0
  877.       if (yydebug)
  878.     fprintf(stderr, "Now at end of input.\n");
  879. #endif
  880.     }
  881.   else
  882.     {
  883.       yychar1 = YYTRANSLATE(yychar);
  884.  
  885. #if YYDEBUG != 0
  886.       if (yydebug)
  887.     {
  888.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  889.       /* Give the individual parser a way to print the precise meaning
  890.          of a token, for further debugging info.  */
  891. #ifdef YYPRINT
  892.       YYPRINT (stderr, yychar, yylval);
  893. #endif
  894.       fprintf (stderr, ")\n");
  895.     }
  896. #endif
  897.     }
  898.  
  899.   yyn += yychar1;
  900.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  901.     goto yydefault;
  902.  
  903.   yyn = yytable[yyn];
  904.  
  905.   /* yyn is what to do for this token type in this state.
  906.      Negative => reduce, -yyn is rule number.
  907.      Positive => shift, yyn is new state.
  908.        New state is final state => don't bother to shift,
  909.        just return success.
  910.      0, or most negative number => error.  */
  911.  
  912.   if (yyn < 0)
  913.     {
  914.       if (yyn == YYFLAG)
  915.     goto yyerrlab;
  916.       yyn = -yyn;
  917.       goto yyreduce;
  918.     }
  919.   else if (yyn == 0)
  920.     goto yyerrlab;
  921.  
  922.   if (yyn == YYFINAL)
  923.     YYACCEPT;
  924.  
  925.   /* Shift the lookahead token.  */
  926.  
  927. #if YYDEBUG != 0
  928.   if (yydebug)
  929.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  930. #endif
  931.  
  932.   /* Discard the token being shifted unless it is eof.  */
  933.   if (yychar != YYEOF)
  934.     yychar = YYEMPTY;
  935.  
  936.   *++yyvsp = yylval;
  937. #ifdef YYLSP_NEEDED
  938.   *++yylsp = yylloc;
  939. #endif
  940.  
  941.   /* count tokens shifted since error; after three, turn off error status.  */
  942.   if (yyerrstatus) yyerrstatus--;
  943.  
  944.   yystate = yyn;
  945.   goto yynewstate;
  946.  
  947. /* Do the default action for the current state.  */
  948. yydefault:
  949.  
  950.   yyn = yydefact[yystate];
  951.   if (yyn == 0)
  952.     goto yyerrlab;
  953.  
  954. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  955. yyreduce:
  956.   yylen = yyr2[yyn];
  957.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  958.  
  959. #if YYDEBUG != 0
  960.   if (yydebug)
  961.     {
  962.       int i;
  963.  
  964.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  965.            yyn, yyrline[yyn]);
  966.  
  967.       /* Print the symboles being reduced, and their result.  */
  968.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  969.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  970.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  971.     }
  972. #endif
  973.  
  974.  
  975.   switch (yyn) {
  976.  
  977. case 1:
  978. #line 164 "./parse.y"
  979. {
  980.               /* Case of regular command.  Discard the error
  981.                  safety net,and return the command just parsed. */
  982.               global_command = yyvsp[-1].command;
  983.               eof_encountered = 0;
  984.               discard_parser_constructs (0);
  985.               YYACCEPT;
  986.             ;
  987.     break;}
  988. case 2:
  989. #line 173 "./parse.y"
  990. {
  991.               /* Case of regular command, but not a very
  992.                  interesting one.  Return a NULL command. */
  993.               global_command = (COMMAND *)NULL;
  994.               YYACCEPT;
  995.             ;
  996.     break;}
  997. case 3:
  998. #line 181 "./parse.y"
  999. {
  1000.               /* Error during parsing.  Return NULL command. */
  1001.               global_command = (COMMAND *)NULL;
  1002.               eof_encountered = 0;
  1003.               discard_parser_constructs (1);
  1004.               if (interactive)
  1005.                 {
  1006.                   YYACCEPT;
  1007.                 }
  1008.               else
  1009.                 {
  1010.                   YYABORT;
  1011.                 }
  1012.             ;
  1013.     break;}
  1014. case 4:
  1015. #line 196 "./parse.y"
  1016. {
  1017.               /* Case of EOF seen by itself.  Do ignoreeof or 
  1018.                  not. */
  1019.               global_command = (COMMAND *)NULL;
  1020.               handle_eof_input_unit ();
  1021.               YYACCEPT;
  1022.             ;
  1023.     break;}
  1024. case 5:
  1025. #line 206 "./parse.y"
  1026. { yyval.word_list = (WORD_LIST *)NULL; ;
  1027.     break;}
  1028. case 6:
  1029. #line 208 "./parse.y"
  1030. { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-1].word_list); ;
  1031.     break;}
  1032. case 7:
  1033. #line 212 "./parse.y"
  1034. {
  1035.               redir.filename = yyvsp[0].word;
  1036.               yyval.redirect = make_redirection (1, r_output_direction, redir);
  1037.             ;
  1038.     break;}
  1039. case 8:
  1040. #line 217 "./parse.y"
  1041. {
  1042.               redir.filename = yyvsp[0].word;
  1043.               yyval.redirect = make_redirection (0, r_input_direction, redir);
  1044.             ;
  1045.     break;}
  1046. case 9:
  1047. #line 222 "./parse.y"
  1048. {
  1049.               redir.filename = yyvsp[0].word;
  1050.               yyval.redirect = make_redirection (yyvsp[-2].number, r_output_direction, redir);
  1051.             ;
  1052.     break;}
  1053. case 10:
  1054. #line 227 "./parse.y"
  1055. {
  1056.               redir.filename = yyvsp[0].word;
  1057.               yyval.redirect = make_redirection (yyvsp[-2].number, r_input_direction, redir);
  1058.             ;
  1059.     break;}
  1060. case 11:
  1061. #line 232 "./parse.y"
  1062. {
  1063.               redir.filename = yyvsp[0].word;
  1064.               yyval.redirect = make_redirection (1, r_appending_to, redir);
  1065.             ;
  1066.     break;}
  1067. case 12:
  1068. #line 237 "./parse.y"
  1069. {
  1070.               redir.filename = yyvsp[0].word;
  1071.               yyval.redirect = make_redirection (yyvsp[-2].number, r_appending_to, redir);
  1072.             ;
  1073.     break;}
  1074. case 13:
  1075. #line 242 "./parse.y"
  1076. {
  1077.               redir.filename = yyvsp[0].word;
  1078.               yyval.redirect = make_redirection (0, r_reading_until, redir);
  1079.               redir_stack[need_here_doc++] = yyval.redirect;
  1080.             ;
  1081.     break;}
  1082. case 14:
  1083. #line 248 "./parse.y"
  1084. {
  1085.               redir.filename = yyvsp[0].word;
  1086.               yyval.redirect = make_redirection (yyvsp[-2].number, r_reading_until, redir);
  1087.               redir_stack[need_here_doc++] = yyval.redirect;
  1088.             ;
  1089.     break;}
  1090. case 15:
  1091. #line 254 "./parse.y"
  1092. {
  1093.               redir.dest = yyvsp[0].number;
  1094.               yyval.redirect = make_redirection (0, r_duplicating_input, redir);
  1095.             ;
  1096.     break;}
  1097. case 16:
  1098. #line 259 "./parse.y"
  1099. {
  1100.               redir.dest = yyvsp[0].number;
  1101.               yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_input, redir);
  1102.             ;
  1103.     break;}
  1104. case 17:
  1105. #line 264 "./parse.y"
  1106. {
  1107.               redir.dest = yyvsp[0].number;
  1108.               yyval.redirect = make_redirection (1, r_duplicating_output, redir);
  1109.             ;
  1110.     break;}
  1111. case 18:
  1112. #line 269 "./parse.y"
  1113. {
  1114.               redir.dest = yyvsp[0].number;
  1115.               yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_output, redir);
  1116.             ;
  1117.     break;}
  1118. case 19:
  1119. #line 274 "./parse.y"
  1120. {
  1121.               redir.filename = yyvsp[0].word;
  1122.               yyval.redirect = make_redirection (0, r_duplicating_input_word, redir);
  1123.             ;
  1124.     break;}
  1125. case 20:
  1126. #line 279 "./parse.y"
  1127. {
  1128.               redir.filename = yyvsp[0].word;
  1129.               yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_input_word, redir);
  1130.             ;
  1131.     break;}
  1132. case 21:
  1133. #line 284 "./parse.y"
  1134. {
  1135.               redir.filename = yyvsp[0].word;
  1136.               yyval.redirect = make_redirection (1, r_duplicating_output_word, redir);
  1137.             ;
  1138.     break;}
  1139. case 22:
  1140. #line 289 "./parse.y"
  1141. {
  1142.               redir.filename = yyvsp[0].word;
  1143.               yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating_output_word, redir);
  1144.             ;
  1145.     break;}
  1146. case 23:
  1147. #line 294 "./parse.y"
  1148. {
  1149.               redir.filename = yyvsp[0].word;
  1150.               yyval.redirect = make_redirection
  1151.                 (0, r_deblank_reading_until, redir);
  1152.               redir_stack[need_here_doc++] = yyval.redirect;
  1153.             ;
  1154.     break;}
  1155. case 24:
  1156. #line 301 "./parse.y"
  1157. {
  1158.               redir.filename = yyvsp[0].word;
  1159.               yyval.redirect = make_redirection
  1160.                 (yyvsp[-2].number, r_deblank_reading_until, redir);
  1161.               redir_stack[need_here_doc++] = yyval.redirect;
  1162.             ;
  1163.     break;}
  1164. case 25:
  1165. #line 308 "./parse.y"
  1166. {
  1167.               redir.dest = 0L;
  1168.               yyval.redirect = make_redirection (1, r_close_this, redir);
  1169.             ;
  1170.     break;}
  1171. case 26:
  1172. #line 313 "./parse.y"
  1173. {
  1174.               redir.dest = 0L;
  1175.               yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, redir);
  1176.             ;
  1177.     break;}
  1178. case 27:
  1179. #line 318 "./parse.y"
  1180. {
  1181.               redir.dest = 0L;
  1182.               yyval.redirect = make_redirection (0, r_close_this, redir);
  1183.             ;
  1184.     break;}
  1185. case 28:
  1186. #line 323 "./parse.y"
  1187. {
  1188.               redir.dest = 0L;
  1189.               yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, redir);
  1190.             ;
  1191.     break;}
  1192. case 29:
  1193. #line 328 "./parse.y"
  1194. {
  1195.               redir.filename = yyvsp[0].word;
  1196.               yyval.redirect = make_redirection (1, r_err_and_out, redir);
  1197.             ;
  1198.     break;}
  1199. case 30:
  1200. #line 333 "./parse.y"
  1201. {
  1202.               redir.filename = yyvsp[0].word;
  1203.               yyval.redirect = make_redirection (yyvsp[-2].number, r_input_output, redir);
  1204.             ;
  1205.     break;}
  1206. case 31:
  1207. #line 338 "./parse.y"
  1208. {
  1209.               REDIRECT *t1, *t2;
  1210.  
  1211.               redir.filename = yyvsp[0].word;
  1212.               if (posixly_correct)
  1213.                 yyval.redirect = make_redirection (0, r_input_output, redir);
  1214.               else
  1215.                 {
  1216.                   t1 = make_redirection (0, r_input_direction, redir);
  1217.                   redir.filename = copy_word (yyvsp[0].word);
  1218.                   t2 = make_redirection (1, r_output_direction, redir);
  1219.                   t1->next = t2;
  1220.                   yyval.redirect = t1;
  1221.                 }
  1222.             ;
  1223.     break;}
  1224. case 32:
  1225. #line 354 "./parse.y"
  1226. {
  1227.               redir.filename = yyvsp[0].word;
  1228.               yyval.redirect = make_redirection (1, r_output_force, redir);
  1229.             ;
  1230.     break;}
  1231. case 33:
  1232. #line 359 "./parse.y"
  1233. {
  1234.               redir.filename = yyvsp[0].word;
  1235.               yyval.redirect = make_redirection (yyvsp[-2].number, r_output_force, redir);
  1236.             ;
  1237.     break;}
  1238. case 34:
  1239. #line 366 "./parse.y"
  1240. { yyval.element.word = yyvsp[0].word; yyval.element.redirect = 0; ;
  1241.     break;}
  1242. case 35:
  1243. #line 368 "./parse.y"
  1244. { yyval.element.word = yyvsp[0].word; yyval.element.redirect = 0; ;
  1245.     break;}
  1246. case 36:
  1247. #line 370 "./parse.y"
  1248. { yyval.element.redirect = yyvsp[0].redirect; yyval.element.word = 0; ;
  1249.     break;}
  1250. case 37:
  1251. #line 374 "./parse.y"
  1252. {
  1253.               yyval.redirect = yyvsp[0].redirect;
  1254.             ;
  1255.     break;}
  1256. case 38:
  1257. #line 378 "./parse.y"
  1258.               register REDIRECT *t = yyvsp[-1].redirect;
  1259.  
  1260.               while (t->next)
  1261.                 t = t->next;
  1262.               t->next = yyvsp[0].redirect; 
  1263.               yyval.redirect = yyvsp[-1].redirect;
  1264.             ;
  1265.     break;}
  1266. case 39:
  1267. #line 389 "./parse.y"
  1268. { yyval.command = make_simple_command (yyvsp[0].element, (COMMAND *)NULL); ;
  1269.     break;}
  1270. case 40:
  1271. #line 391 "./parse.y"
  1272. { yyval.command = make_simple_command (yyvsp[0].element, yyvsp[-1].command); ;
  1273.     break;}
  1274. case 41:
  1275. #line 395 "./parse.y"
  1276. { yyval.command = clean_simple_command (yyvsp[0].command); ;
  1277.     break;}
  1278. case 42:
  1279. #line 397 "./parse.y"
  1280. { yyval.command = yyvsp[0].command; ;
  1281.     break;}
  1282. case 43:
  1283. #line 401 "./parse.y"
  1284. { yyval.command = yyvsp[0].command; ;
  1285.     break;}
  1286. case 44:
  1287. #line 403 "./parse.y"
  1288. {
  1289.               if (yyvsp[-1].command->redirects)
  1290.                 {
  1291.                   register REDIRECT *t;
  1292.                   for (t = yyvsp[-1].command->redirects; t->next; t = t->next)
  1293.                 ;
  1294.                   t->next = yyvsp[0].redirect;
  1295.                 }
  1296.               else
  1297.                 yyvsp[-1].command->redirects = yyvsp[0].redirect;
  1298.               yyval.command = yyvsp[-1].command;
  1299.             ;
  1300.     break;}
  1301. case 45:
  1302. #line 418 "./parse.y"
  1303. { yyval.command = make_for_command (yyvsp[-4].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  1304.     break;}
  1305. case 46:
  1306. #line 420 "./parse.y"
  1307. { yyval.command = make_for_command (yyvsp[-4].word, add_string_to_list ("$@", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  1308.     break;}
  1309. case 47:
  1310. #line 422 "./parse.y"
  1311. { yyval.command = make_for_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  1312.     break;}
  1313. case 48:
  1314. #line 424 "./parse.y"
  1315. { yyval.command = make_for_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  1316.     break;}
  1317. case 49:
  1318. #line 426 "./parse.y"
  1319. { yyval.command = make_for_command (yyvsp[-8].word, REVERSE_LIST (yyvsp[-5].word_list, WORD_LIST *), yyvsp[-1].command); ;
  1320.     break;}
  1321. case 50:
  1322. #line 428 "./parse.y"
  1323. { yyval.command = make_for_command (yyvsp[-8].word, REVERSE_LIST (yyvsp[-5].word_list, WORD_LIST *), yyvsp[-1].command); ;
  1324.     break;}
  1325. case 51:
  1326. #line 431 "./parse.y"
  1327. { yyval.command = make_case_command (yyvsp[-4].word, (PATTERN_LIST *)NULL); ;
  1328.     break;}
  1329. case 52:
  1330. #line 433 "./parse.y"
  1331. { yyval.command = make_case_command (yyvsp[-5].word, yyvsp[-2].pattern); ;
  1332.     break;}
  1333. case 53:
  1334. #line 435 "./parse.y"
  1335. { yyval.command = make_case_command (yyvsp[-4].word, yyvsp[-1].pattern); ;
  1336.     break;}
  1337. case 54:
  1338. #line 437 "./parse.y"
  1339. { yyval.command = make_while_command (yyvsp[-3].command, yyvsp[-1].command); ;
  1340.     break;}
  1341. case 55:
  1342. #line 439 "./parse.y"
  1343. { yyval.command = make_until_command (yyvsp[-3].command, yyvsp[-1].command); ;
  1344.     break;}
  1345. case 56:
  1346. #line 441 "./parse.y"
  1347. { yyval.command = yyvsp[0].command; ;
  1348.     break;}
  1349. case 57:
  1350. #line 443 "./parse.y"
  1351. { yyval.command = yyvsp[0].command; ;
  1352.     break;}
  1353. case 58:
  1354. #line 445 "./parse.y"
  1355. { yyval.command = yyvsp[0].command; ;
  1356.     break;}
  1357. case 59:
  1358. #line 447 "./parse.y"
  1359. { yyval.command = yyvsp[0].command; ;
  1360.     break;}
  1361. case 60:
  1362. #line 449 "./parse.y"
  1363. { yyval.command = yyvsp[0].command; ;
  1364.     break;}
  1365. case 61:
  1366. #line 453 "./parse.y"
  1367. {
  1368. #if defined (SELECT_COMMAND)
  1369.               yyval.command = make_select_command (yyvsp[-4].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
  1370. #endif
  1371.             ;
  1372.     break;}
  1373. case 62:
  1374. #line 459 "./parse.y"
  1375. {
  1376. #if defined (SELECT_COMMAND)
  1377.               yyval.command = make_select_command (yyvsp[-4].word, add_string_to_list ("$@", (WORD_LIST *)NULL), yyvsp[-1].command);
  1378. #endif
  1379.             ;
  1380.     break;}
  1381. case 63:
  1382. #line 465 "./parse.y"
  1383. {
  1384. #if defined (SELECT_COMMAND)
  1385.               yyval.command = make_select_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
  1386. #endif
  1387.             ;
  1388.     break;}
  1389. case 64:
  1390. #line 471 "./parse.y"
  1391. {
  1392. #if defined (SELECT_COMMAND)
  1393.               yyval.command = make_select_command (yyvsp[-5].word, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command);
  1394. #endif
  1395.             ;
  1396.     break;}
  1397. case 65:
  1398. #line 477 "./parse.y"
  1399. {
  1400. #if defined (SELECT_COMMAND)
  1401.               yyval.command = make_select_command (yyvsp[-8].word, (WORD_LIST *)reverse_list (yyvsp[-5].word_list), yyvsp[-1].command);
  1402. #endif
  1403.             ;
  1404.     break;}
  1405. case 66:
  1406. #line 483 "./parse.y"
  1407. {
  1408. #if defined (SELECT_COMMAND)
  1409.               yyval.command = make_select_command (yyvsp[-8].word, (WORD_LIST *)reverse_list (yyvsp[-5].word_list), yyvsp[-1].command);
  1410. #endif
  1411.             ;
  1412.     break;}
  1413. case 67:
  1414. #line 491 "./parse.y"
  1415. { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command); ;
  1416.     break;}
  1417. case 68:
  1418. #line 494 "./parse.y"
  1419. { yyvsp[-1].command->redirects = yyvsp[0].redirect; yyval.command = make_function_def (yyvsp[-5].word, yyvsp[-1].command); ;
  1420.     break;}
  1421. case 69:
  1422. #line 497 "./parse.y"
  1423. { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command); ;
  1424.     break;}
  1425. case 70:
  1426. #line 500 "./parse.y"
  1427. { yyvsp[-1].command->redirects = yyvsp[0].redirect; yyval.command = make_function_def (yyvsp[-5].word, yyvsp[-1].command); ;
  1428.     break;}
  1429. case 71:
  1430. #line 503 "./parse.y"
  1431. { yyval.command = make_function_def (yyvsp[-2].word, yyvsp[0].command); ;
  1432.     break;}
  1433. case 72:
  1434. #line 506 "./parse.y"
  1435. { yyvsp[-1].command->redirects = yyvsp[0].redirect; yyval.command = make_function_def (yyvsp[-3].word, yyvsp[-1].command); ;
  1436.     break;}
  1437. case 73:
  1438. #line 510 "./parse.y"
  1439. { yyvsp[-1].command->flags |= CMD_WANT_SUBSHELL; yyval.command = yyvsp[-1].command; ;
  1440.     break;}
  1441. case 74:
  1442. #line 514 "./parse.y"
  1443. { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, (COMMAND *)NULL); ;
  1444.     break;}
  1445. case 75:
  1446. #line 516 "./parse.y"
  1447. { yyval.command = make_if_command (yyvsp[-5].command, yyvsp[-3].command, yyvsp[-1].command); ;
  1448.     break;}
  1449. case 76:
  1450. #line 518 "./parse.y"
  1451. { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[-1].command); ;
  1452.     break;}
  1453. case 77:
  1454. #line 523 "./parse.y"
  1455. { yyval.command = make_group_command (yyvsp[-1].command); ;
  1456.     break;}
  1457. case 78:
  1458. #line 527 "./parse.y"
  1459. { yyval.command = make_if_command (yyvsp[-2].command, yyvsp[0].command, (COMMAND *)NULL); ;
  1460.     break;}
  1461. case 79:
  1462. #line 529 "./parse.y"
  1463. { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[0].command); ;
  1464.     break;}
  1465. case 80:
  1466. #line 531 "./parse.y"
  1467. { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, yyvsp[0].command); ;
  1468.     break;}
  1469. case 82:
  1470. #line 536 "./parse.y"
  1471. { yyvsp[0].pattern->next = yyvsp[-1].pattern; yyval.pattern = yyvsp[0].pattern; ;
  1472.     break;}
  1473. case 83:
  1474. #line 540 "./parse.y"
  1475. { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, yyvsp[0].command); ;
  1476.     break;}
  1477. case 84:
  1478. #line 542 "./parse.y"
  1479. { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, (COMMAND *)NULL); ;
  1480.     break;}
  1481. case 85:
  1482. #line 544 "./parse.y"
  1483. { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, yyvsp[0].command); ;
  1484.     break;}
  1485. case 86:
  1486. #line 546 "./parse.y"
  1487. { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, (COMMAND *)NULL); ;
  1488.     break;}
  1489. case 88:
  1490. #line 551 "./parse.y"
  1491. { yyvsp[0].pattern->next = yyvsp[-1].pattern; yyval.pattern = yyvsp[0].pattern; ;
  1492.     break;}
  1493. case 89:
  1494. #line 555 "./parse.y"
  1495. { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, yyvsp[-1].command); ;
  1496.     break;}
  1497. case 90:
  1498. #line 557 "./parse.y"
  1499. { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, (COMMAND *)NULL); ;
  1500.     break;}
  1501. case 91:
  1502. #line 559 "./parse.y"
  1503. { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, yyvsp[-1].command); ;
  1504.     break;}
  1505. case 92:
  1506. #line 561 "./parse.y"
  1507. { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, (COMMAND *)NULL); ;
  1508.     break;}
  1509. case 93:
  1510. #line 565 "./parse.y"
  1511. { yyval.word_list = make_word_list (yyvsp[0].word, (WORD_LIST *)NULL); ;
  1512.     break;}
  1513. case 94:
  1514. #line 567 "./parse.y"
  1515. { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-2].word_list); ;
  1516.     break;}
  1517. case 95:
  1518. #line 576 "./parse.y"
  1519. {
  1520.               yyval.command = yyvsp[0].command;
  1521.               if (need_here_doc)
  1522.                 gather_here_documents ();
  1523.              ;
  1524.     break;}
  1525. case 98:
  1526. #line 586 "./parse.y"
  1527. {
  1528.               if (yyvsp[-2].command->type == cm_connection)
  1529.                 yyval.command = connect_async_list (yyvsp[-2].command, (COMMAND *)NULL, '&');
  1530.               else
  1531.                 yyval.command = command_connect (yyvsp[-2].command, (COMMAND *)NULL, '&');
  1532.             ;
  1533.     break;}
  1534. case 100:
  1535. #line 597 "./parse.y"
  1536. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); ;
  1537.     break;}
  1538. case 101:
  1539. #line 599 "./parse.y"
  1540. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); ;
  1541.     break;}
  1542. case 102:
  1543. #line 601 "./parse.y"
  1544. {
  1545.               if (yyvsp[-3].command->type == cm_connection)
  1546.                 yyval.command = connect_async_list (yyvsp[-3].command, yyvsp[0].command, '&');
  1547.               else
  1548.                 yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '&');
  1549.             ;
  1550.     break;}
  1551. case 103:
  1552. #line 608 "./parse.y"
  1553. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); ;
  1554.     break;}
  1555. case 104:
  1556. #line 610 "./parse.y"
  1557. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); ;
  1558.     break;}
  1559. case 105:
  1560. #line 612 "./parse.y"
  1561. { yyval.command = yyvsp[0].command; ;
  1562.     break;}
  1563. case 106:
  1564. #line 614 "./parse.y"
  1565. {
  1566.               yyvsp[0].command->flags |= CMD_INVERT_RETURN;
  1567.               yyval.command = yyvsp[0].command;
  1568.             ;
  1569.     break;}
  1570. case 112:
  1571. #line 636 "./parse.y"
  1572. {
  1573.               yyval.command = yyvsp[0].command;
  1574.               if (need_here_doc)
  1575.                 gather_here_documents ();
  1576.             ;
  1577.     break;}
  1578. case 113:
  1579. #line 642 "./parse.y"
  1580. {
  1581.               if (yyvsp[-1].command->type == cm_connection)
  1582.                 yyval.command = connect_async_list (yyvsp[-1].command, (COMMAND *)NULL, '&');
  1583.               else
  1584.                 yyval.command = command_connect (yyvsp[-1].command, (COMMAND *)NULL, '&');
  1585.               if (need_here_doc)
  1586.                 gather_here_documents ();
  1587.             ;
  1588.     break;}
  1589. case 114:
  1590. #line 651 "./parse.y"
  1591. {
  1592.               yyval.command = yyvsp[-1].command;
  1593.               if (need_here_doc)
  1594.                 gather_here_documents ();
  1595.             ;
  1596.     break;}
  1597. case 115:
  1598. #line 659 "./parse.y"
  1599. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); ;
  1600.     break;}
  1601. case 116:
  1602. #line 661 "./parse.y"
  1603. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); ;
  1604.     break;}
  1605. case 117:
  1606. #line 663 "./parse.y"
  1607. {
  1608.               if (yyvsp[-2].command->type == cm_connection)
  1609.                 yyval.command = connect_async_list (yyvsp[-2].command, yyvsp[0].command, '&');
  1610.               else
  1611.                 yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, '&');
  1612.             ;
  1613.     break;}
  1614. case 118:
  1615. #line 670 "./parse.y"
  1616. { yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, ';'); ;
  1617.     break;}
  1618. case 119:
  1619. #line 672 "./parse.y"
  1620. { yyval.command = yyvsp[0].command; ;
  1621.     break;}
  1622. case 120:
  1623. #line 674 "./parse.y"
  1624. {
  1625.               yyvsp[0].command->flags |= CMD_INVERT_RETURN;
  1626.               yyval.command = yyvsp[0].command;
  1627.             ;
  1628.     break;}
  1629. case 121:
  1630. #line 682 "./parse.y"
  1631. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '|'); ;
  1632.     break;}
  1633. case 122:
  1634. #line 684 "./parse.y"
  1635. { yyval.command = yyvsp[0].command; ;
  1636.     break;}
  1637. }
  1638.    /* the action file gets copied in in place of this dollarsign */
  1639. #line 440 "/usr/local/lib/bison.simple"
  1640.  
  1641.   yyvsp -= yylen;
  1642.   yyssp -= yylen;
  1643. #ifdef YYLSP_NEEDED
  1644.   yylsp -= yylen;
  1645. #endif
  1646.  
  1647. #if YYDEBUG != 0
  1648.   if (yydebug)
  1649.     {
  1650.       short *ssp1 = yyss - 1;
  1651.       fprintf (stderr, "state stack now");
  1652.       while (ssp1 != yyssp)
  1653.     fprintf (stderr, " %d", *++ssp1);
  1654.       fprintf (stderr, "\n");
  1655.     }
  1656. #endif
  1657.  
  1658.   *++yyvsp = yyval;
  1659.  
  1660. #ifdef YYLSP_NEEDED
  1661.   yylsp++;
  1662.   if (yylen == 0)
  1663.     {
  1664.       yylsp->first_line = yylloc.first_line;
  1665.       yylsp->first_column = yylloc.first_column;
  1666.       yylsp->last_line = (yylsp-1)->last_line;
  1667.       yylsp->last_column = (yylsp-1)->last_column;
  1668.       yylsp->text = 0;
  1669.     }
  1670.   else
  1671.     {
  1672.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1673.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1674.     }
  1675. #endif
  1676.  
  1677.   /* Now "shift" the result of the reduction.
  1678.      Determine what state that goes to,
  1679.      based on the state we popped back to
  1680.      and the rule number reduced by.  */
  1681.  
  1682.   yyn = yyr1[yyn];
  1683.  
  1684.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1685.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1686.     yystate = yytable[yystate];
  1687.   else
  1688.     yystate = yydefgoto[yyn - YYNTBASE];
  1689.  
  1690.   goto yynewstate;
  1691.  
  1692. yyerrlab:   /* here on detecting error */
  1693.  
  1694.   if (! yyerrstatus)
  1695.     /* If not already recovering from an error, report this error.  */
  1696.     {
  1697.       ++yynerrs;
  1698.  
  1699. #ifdef YYERROR_VERBOSE
  1700.       yyn = yypact[yystate];
  1701.  
  1702.       if (yyn > YYFLAG && yyn < YYLAST)
  1703.     {
  1704.       int size = 0;
  1705.       char *msg;
  1706.       int x, count;
  1707.  
  1708.       count = 0;
  1709.       for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1710.         if (yycheck[x + yyn] == x)
  1711.           size += strlen(yytname[x]) + 15, count++;
  1712.       msg = (char *) malloc(size + 15);
  1713.       if (msg != 0)
  1714.         {
  1715.           strcpy(msg, "parse error");
  1716.  
  1717.           if (count < 5)
  1718.         {
  1719.           count = 0;
  1720.           for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1721.             if (yycheck[x + yyn] == x)
  1722.               {
  1723.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1724.             strcat(msg, yytname[x]);
  1725.             strcat(msg, "'");
  1726.             count++;
  1727.               }
  1728.         }
  1729.           yyerror(msg);
  1730.           free(msg);
  1731.         }
  1732.       else
  1733.         yyerror ("parse error; also virtual memory exceeded");
  1734.     }
  1735.       else
  1736. #endif /* YYERROR_VERBOSE */
  1737.     yyerror("parse error");
  1738.     }
  1739.  
  1740. yyerrlab1:   /* here on error raised explicitly by an action */
  1741.  
  1742.   if (yyerrstatus == 3)
  1743.     {
  1744.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1745.  
  1746.       /* return failure if at end of input */
  1747.       if (yychar == YYEOF)
  1748.     YYABORT;
  1749.  
  1750. #if YYDEBUG != 0
  1751.       if (yydebug)
  1752.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1753. #endif
  1754.  
  1755.       yychar = YYEMPTY;
  1756.     }
  1757.  
  1758.   /* Else will try to reuse lookahead token
  1759.      after shifting the error token.  */
  1760.  
  1761.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1762.  
  1763.   goto yyerrhandle;
  1764.  
  1765. yyerrdefault:  /* current state does not do anything special for the error token. */
  1766.  
  1767. #if 0
  1768.   /* This is wrong; only states that explicitly want error tokens
  1769.      should shift them.  */
  1770.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1771.   if (yyn) goto yydefault;
  1772. #endif
  1773.  
  1774. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1775.  
  1776.   if (yyssp == yyss) YYABORT;
  1777.   yyvsp--;
  1778.   yystate = *--yyssp;
  1779. #ifdef YYLSP_NEEDED
  1780.   yylsp--;
  1781. #endif
  1782.  
  1783. #if YYDEBUG != 0
  1784.   if (yydebug)
  1785.     {
  1786.       short *ssp1 = yyss - 1;
  1787.       fprintf (stderr, "Error: state stack now");
  1788.       while (ssp1 != yyssp)
  1789.     fprintf (stderr, " %d", *++ssp1);
  1790.       fprintf (stderr, "\n");
  1791.     }
  1792. #endif
  1793.  
  1794. yyerrhandle:
  1795.  
  1796.   yyn = yypact[yystate];
  1797.   if (yyn == YYFLAG)
  1798.     goto yyerrdefault;
  1799.  
  1800.   yyn += YYTERROR;
  1801.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1802.     goto yyerrdefault;
  1803.  
  1804.   yyn = yytable[yyn];
  1805.   if (yyn < 0)
  1806.     {
  1807.       if (yyn == YYFLAG)
  1808.     goto yyerrpop;
  1809.       yyn = -yyn;
  1810.       goto yyreduce;
  1811.     }
  1812.   else if (yyn == 0)
  1813.     goto yyerrpop;
  1814.  
  1815.   if (yyn == YYFINAL)
  1816.     YYACCEPT;
  1817.  
  1818. #if YYDEBUG != 0
  1819.   if (yydebug)
  1820.     fprintf(stderr, "Shifting error token, ");
  1821. #endif
  1822.  
  1823.   *++yyvsp = yylval;
  1824. #ifdef YYLSP_NEEDED
  1825.   *++yylsp = yylloc;
  1826. #endif
  1827.  
  1828.   yystate = yyn;
  1829.   goto yynewstate;
  1830. }
  1831. #line 686 "./parse.y"
  1832.  
  1833.  
  1834. /* Initial size to allocate for tokens, and the
  1835.    amount to grow them by. */
  1836. #define TOKEN_DEFAULT_GROW_SIZE 512
  1837.  
  1838. /* The token currently being read. */
  1839. static int current_token = 0;
  1840.  
  1841. /* The last read token, or NULL.  read_token () uses this for context
  1842.    checking. */
  1843. static int last_read_token = 0;
  1844.  
  1845. /* The token read prior to last_read_token. */
  1846. static int token_before_that = 0;
  1847.  
  1848. /* If non-zero, it is the token that we want read_token to return
  1849.    regardless of what text is (or isn't) present to be read.  This
  1850.    is reset by read_token. */
  1851. static int token_to_read = 0;
  1852.  
  1853. /* Global var is non-zero when end of file has been reached. */
  1854. int EOF_Reached = 0;
  1855.  
  1856. /* yy_getc () returns the next available character from input or EOF.
  1857.    yy_ungetc (c) makes `c' the next character to read.
  1858.    init_yy_io (get, unget, type, location) makes the function GET the
  1859.    installed function for getting the next character, makes UNGET the
  1860.    installed function for un-getting a character, sets the type of stream
  1861.    (either string or file) from TYPE, and makes LOCATION point to where
  1862.    the input is coming from. */
  1863.  
  1864. /* Unconditionally returns end-of-file. */
  1865. return_EOF ()
  1866. {
  1867.   return (EOF);
  1868. }
  1869.  
  1870. /* Variable containing the current get and unget functions.
  1871.    See ./input.h for a clearer description. */
  1872. BASH_INPUT bash_input;
  1873.  
  1874. /* Set all of the fields in BASH_INPUT to NULL. */
  1875. void
  1876. initialize_bash_input ()
  1877. {
  1878.   bash_input.type = 0;
  1879.   bash_input.name = (char *)NULL;
  1880.   bash_input.location.file = (FILE *)NULL;
  1881.   bash_input.location.string = (char *)NULL;
  1882.   bash_input.getter = (Function *)NULL;
  1883.   bash_input.ungetter = (Function *)NULL;
  1884. }
  1885.  
  1886. /* Set the contents of the current bash input stream from
  1887.    GET, UNGET, TYPE, NAME, and LOCATION. */
  1888. void
  1889. init_yy_io (get, unget, type, name, location)
  1890.      Function *get, *unget;
  1891.      int type;
  1892.      char *name;
  1893.      INPUT_STREAM location;
  1894. {
  1895.   bash_input.type = type;
  1896.   FREE (bash_input.name);
  1897.  
  1898.   if (name)
  1899.     bash_input.name = savestring (name);
  1900.   else
  1901.     bash_input.name = (char *)NULL;
  1902.  
  1903. #if defined (CRAY)
  1904.   memcpy((char *)&bash_input.location.string, (char *)&location.string, sizeof(location));
  1905. #else
  1906.   bash_input.location = location;
  1907. #endif
  1908.   bash_input.getter = get;
  1909.   bash_input.ungetter = unget;
  1910. }
  1911.  
  1912. /* Call this to get the next character of input. */
  1913. yy_getc ()
  1914. {
  1915.   return (*(bash_input.getter)) ();
  1916. }
  1917.  
  1918. /* Call this to unget C.  That is, to make C the next character
  1919.    to be read. */
  1920. yy_ungetc (c)
  1921.      int c;
  1922. {
  1923.   return (*(bash_input.ungetter)) (c);
  1924. }
  1925.  
  1926. #if defined (BUFFERED_INPUT)
  1927. int
  1928. input_file_descriptor ()
  1929. {
  1930.   switch (bash_input.type)
  1931.     {
  1932.     case st_stream:
  1933.       return (fileno (bash_input.location.file));
  1934.     case st_bstream:
  1935.       return (bash_input.location.buffered_fd);
  1936.     default:
  1937.       return (fileno (stdin));
  1938.     }
  1939. }
  1940. #endif /* BUFFERED_INPUT */
  1941.  
  1942. /* **************************************************************** */
  1943. /*                                    */
  1944. /*          Let input be read from readline ().            */
  1945. /*                                    */
  1946. /* **************************************************************** */
  1947.  
  1948. #if defined (READLINE)
  1949. char *current_readline_prompt = (char *)NULL;
  1950. char *current_readline_line = (char *)NULL;
  1951. int current_readline_line_index = 0;
  1952.  
  1953. static int
  1954. yy_readline_get ()
  1955. {
  1956.   if (!current_readline_line)
  1957.     {
  1958.       SigHandler *old_sigint;
  1959.       int line_len;
  1960.  
  1961.       if (!bash_readline_initialized)
  1962.     initialize_readline ();
  1963.  
  1964. #if defined (JOB_CONTROL)
  1965.       if (job_control)
  1966.     give_terminal_to (shell_pgrp);
  1967. #endif /* JOB_CONTROL */
  1968.  
  1969.       old_sigint = (SigHandler *)set_signal_handler (SIGINT, sigint_sighandler);
  1970.       interrupt_immediately++;
  1971.  
  1972.       if (!current_readline_prompt)
  1973.     current_readline_line = readline ("");
  1974.       else
  1975.     current_readline_line = readline (current_readline_prompt);
  1976.  
  1977.       interrupt_immediately--;
  1978.       set_signal_handler (SIGINT, old_sigint);
  1979.  
  1980.       /* Reset the prompt to whatever is in the decoded value of
  1981.      prompt_string_pointer. */
  1982.       reset_readline_prompt ();
  1983.  
  1984.       current_readline_line_index = 0;
  1985.  
  1986.       if (!current_readline_line)
  1987.     return (EOF);
  1988.  
  1989.       line_len = strlen (current_readline_line);
  1990.       current_readline_line = xrealloc (current_readline_line, 2 + line_len);
  1991.       current_readline_line[line_len++] = '\n';
  1992.       current_readline_line[line_len] = '\0';
  1993.     }
  1994.  
  1995.   if (!current_readline_line[current_readline_line_index])
  1996.     {
  1997.       free (current_readline_line);
  1998.       current_readline_line = (char *)NULL;
  1999.       return (yy_readline_get ());
  2000.     }
  2001.   else
  2002.     {
  2003.       int c = current_readline_line[current_readline_line_index++];
  2004.       return (c);
  2005.     }
  2006. }
  2007.  
  2008. static int
  2009. yy_readline_unget (c)
  2010. {
  2011.   if (current_readline_line_index && current_readline_line)
  2012.     current_readline_line[--current_readline_line_index] = c;
  2013.   return (c);
  2014. }
  2015.  
  2016. void  
  2017. with_input_from_stdin ()
  2018. {
  2019.   INPUT_STREAM location;
  2020.  
  2021.   location.string = current_readline_line;
  2022.   init_yy_io (yy_readline_get, yy_readline_unget,
  2023.           st_string, "readline stdin", location);
  2024. }
  2025.  
  2026. #else  /* !READLINE */
  2027.  
  2028. void
  2029. with_input_from_stdin ()
  2030. {
  2031.   with_input_from_stream (stdin, "stdin");
  2032. }
  2033. #endif    /* !READLINE */
  2034.  
  2035. /* **************************************************************** */
  2036. /*                                    */
  2037. /*   Let input come from STRING.  STRING is zero terminated.        */
  2038. /*                                    */
  2039. /* **************************************************************** */
  2040.  
  2041. static int
  2042. yy_string_get ()
  2043. {
  2044.   register char *string;
  2045.   register int c;
  2046.  
  2047.   string = bash_input.location.string;
  2048.   c = EOF;
  2049.  
  2050.   /* If the string doesn't exist, or is empty, EOF found. */
  2051.   if (string && *string)
  2052.     {
  2053.       c = *string++;
  2054.       bash_input.location.string = string;
  2055.     }
  2056.   return (c);
  2057. }
  2058.  
  2059. static int
  2060. yy_string_unget (c)
  2061.      int c;
  2062. {
  2063.   *(--bash_input.location.string) = c;
  2064.   return (c);
  2065. }
  2066.  
  2067. void
  2068. with_input_from_string (string, name)
  2069.      char *string;
  2070.      char *name;
  2071. {
  2072.   INPUT_STREAM location;
  2073.  
  2074.   location.string = string;
  2075.  
  2076.   init_yy_io (yy_string_get, yy_string_unget, st_string, name, location);
  2077. }
  2078.  
  2079. /* **************************************************************** */
  2080. /*                                    */
  2081. /*             Let input come from STREAM.            */
  2082. /*                                    */
  2083. /* **************************************************************** */
  2084.  
  2085. static int
  2086. yy_stream_get ()
  2087. {
  2088.   int result = EOF;
  2089.  
  2090.   if (bash_input.location.file)
  2091. #if defined (NO_READ_RESTART_ON_SIGNAL)
  2092.     result = getc_with_restart (bash_input.location.file);
  2093. #else
  2094.     result = getc (bash_input.location.file);
  2095. #endif /* !NO_READ_RESTART_ON_SIGNAL */
  2096.   return (result);
  2097. }
  2098.  
  2099. static int
  2100. yy_stream_unget (c)
  2101.      int c;
  2102. {
  2103.   return (ungetc (c, bash_input.location.file));
  2104. }
  2105.  
  2106. void
  2107. with_input_from_stream (stream, name)
  2108.      FILE *stream;
  2109.      char *name;
  2110. {
  2111.   INPUT_STREAM location;
  2112.  
  2113.   location.file = stream;
  2114.   init_yy_io (yy_stream_get, yy_stream_unget, st_stream, name, location);
  2115. }
  2116.  
  2117. typedef struct stream_saver {
  2118.   struct stream_saver *next;
  2119.   BASH_INPUT bash_input;
  2120.   int line;
  2121. #if defined (BUFFERED_INPUT)
  2122.   BUFFERED_STREAM *bstream;
  2123. #endif /* BUFFERED_INPUT */
  2124. } STREAM_SAVER;
  2125.  
  2126. /* The globally known line number. */
  2127. int line_number = 0;
  2128.  
  2129. STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
  2130.  
  2131. push_stream ()
  2132. {
  2133.   STREAM_SAVER *saver = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
  2134.  
  2135.   xbcopy ((char *)&bash_input, (char *)&(saver->bash_input), sizeof (BASH_INPUT));
  2136.  
  2137. #if defined (BUFFERED_INPUT)
  2138.   saver->bstream = (BUFFERED_STREAM *)NULL;
  2139.   /* If we have a buffered stream, clear out buffers[fd]. */
  2140.   if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
  2141.     {
  2142.       saver->bstream = buffers[bash_input.location.buffered_fd];
  2143.       buffers[bash_input.location.buffered_fd] = (BUFFERED_STREAM *)NULL;
  2144.     }
  2145. #endif /* BUFFERED_INPUT */
  2146.  
  2147.   saver->line = line_number;
  2148.   bash_input.name = (char *)NULL;
  2149.   saver->next = stream_list;
  2150.   stream_list = saver;
  2151.   EOF_Reached = line_number = 0;
  2152. }
  2153.  
  2154. pop_stream ()
  2155. {
  2156.   int temp;
  2157.  
  2158.   if (!stream_list)
  2159.     EOF_Reached = 1;
  2160.   else
  2161.     {
  2162.       STREAM_SAVER *saver = stream_list;
  2163.  
  2164.       EOF_Reached = 0;
  2165.       stream_list = stream_list->next;
  2166.  
  2167.       init_yy_io (saver->bash_input.getter,
  2168.           saver->bash_input.ungetter,
  2169.           saver->bash_input.type,
  2170.           saver->bash_input.name,
  2171.           saver->bash_input.location);
  2172.  
  2173. #if defined (BUFFERED_INPUT)
  2174.       /* If we have a buffered stream, restore buffers[fd]. */
  2175.       /* If the input file descriptor was changed while this was on the
  2176.      save stack, update the buffered fd to the new file descriptor and
  2177.      re-establish the buffer <-> bash_input fd correspondence. */
  2178.       if (bash_input.type == st_bstream && bash_input.location.buffered_fd >= 0)
  2179.         {
  2180.           if (bash_input_fd_changed)
  2181.         {
  2182.           bash_input_fd_changed = 0;
  2183.           if (default_buffered_input >= 0)
  2184.         {
  2185.           bash_input.location.buffered_fd = default_buffered_input;
  2186.           saver->bstream->b_fd = default_buffered_input;
  2187.         }
  2188.         }
  2189.       buffers[bash_input.location.buffered_fd] = saver->bstream;
  2190.         }
  2191. #endif /* BUFFERED_INPUT */
  2192.  
  2193.       line_number = saver->line;
  2194.  
  2195.       FREE (saver->bash_input.name);
  2196.       free (saver);
  2197.     }
  2198. }
  2199.  
  2200. /*
  2201.  * This is used to inhibit alias expansion and reserved word recognition
  2202.  * inside case statement pattern lists.  A `case statement pattern list'
  2203.  * is:
  2204.  *    everything between the `in' in a `case word in' and the next ')'
  2205.  *    or `esac'
  2206.  *    everything between a `;;' and the next `)' or `esac'
  2207.  */
  2208. static int in_case_pattern_list = 0;
  2209.  
  2210. #if defined (ALIAS)
  2211. /*
  2212.  * Pseudo-global variables used in implementing token-wise alias expansion.
  2213.  */
  2214.  
  2215. static int expand_next_token = 0;
  2216.  
  2217. /*
  2218.  * Pushing and popping strings.  This works together with shell_getc to 
  2219.  * implement alias expansion on a per-token basis.
  2220.  */
  2221.  
  2222. typedef struct string_saver {
  2223.   struct string_saver *next;
  2224.   int expand_alias;  /* Value to set expand_alias to when string is popped. */
  2225.   char *saved_line;
  2226.   int saved_line_size, saved_line_index, saved_line_terminator;
  2227. } STRING_SAVER;
  2228.  
  2229. STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
  2230.  
  2231. static void save_expansion ();
  2232.  
  2233. /*
  2234.  * Push the current shell_input_line onto a stack of such lines and make S
  2235.  * the current input.  Used when expanding aliases.  EXPAND is used to set
  2236.  * the value of expand_next_token when the string is popped, so that the
  2237.  * word after the alias in the original line is handled correctly when the
  2238.  * alias expands to multiple words.  TOKEN is the token that was expanded
  2239.  * into S; it is saved and used to prevent infinite recursive expansion.
  2240.  */
  2241. static void
  2242. push_string (s, expand, token)
  2243.      char *s;
  2244.      int expand;
  2245.      char *token;
  2246. {
  2247.   STRING_SAVER *temp = (STRING_SAVER *) xmalloc (sizeof (STRING_SAVER));
  2248.  
  2249.   temp->expand_alias = expand;
  2250.   temp->saved_line = shell_input_line;
  2251.   temp->saved_line_size = shell_input_line_size;
  2252.   temp->saved_line_index = shell_input_line_index;
  2253.   temp->saved_line_terminator = shell_input_line_terminator;
  2254.   temp->next = pushed_string_list;
  2255.   pushed_string_list = temp;
  2256.  
  2257.   save_expansion (token);
  2258.  
  2259.   shell_input_line = s;
  2260.   shell_input_line_size = strlen (s);
  2261.   shell_input_line_index = 0;
  2262.   shell_input_line_terminator = '\0';
  2263.   expand_next_token = 0;
  2264. }
  2265.  
  2266. /*
  2267.  * Make the top of the pushed_string stack be the current shell input.
  2268.  * Only called when there is something on the stack.  Called from shell_getc
  2269.  * when it thinks it has consumed the string generated by an alias expansion
  2270.  * and needs to return to the original input line.
  2271.  */
  2272. static void
  2273. pop_string ()
  2274. {
  2275.   STRING_SAVER *t;
  2276.  
  2277.   FREE (shell_input_line);
  2278.   shell_input_line = pushed_string_list->saved_line;
  2279.   shell_input_line_index = pushed_string_list->saved_line_index;
  2280.   shell_input_line_size = pushed_string_list->saved_line_size;
  2281.   shell_input_line_terminator = pushed_string_list->saved_line_terminator;
  2282.   expand_next_token = pushed_string_list->expand_alias;
  2283.  
  2284.   t = pushed_string_list;
  2285.   pushed_string_list = pushed_string_list->next;
  2286.   free((char *)t);
  2287. }
  2288.  
  2289. static void
  2290. free_string_list ()
  2291. {
  2292.   register STRING_SAVER *t = pushed_string_list, *t1;
  2293.  
  2294.   while (t)
  2295.     {
  2296.       t1 = t->next;
  2297.       FREE (t->saved_line);
  2298.       free ((char *)t);
  2299.       t = t1;
  2300.     }
  2301.   pushed_string_list = (STRING_SAVER *)NULL;
  2302. }
  2303.  
  2304. /* This is a stack to save the values of all tokens for which alias
  2305.    expansion has been performed during the current call to read_token ().
  2306.    It is used to prevent alias expansion loops:
  2307.  
  2308.       alias foo=bar
  2309.       alias bar=baz
  2310.       alias baz=foo
  2311.  
  2312.    Ideally this would be taken care of by push and pop string, but because
  2313.    of when strings are popped the stack will not contain the correct
  2314.    strings to test against.  (The popping is done in shell_getc, so that when
  2315.    the current string is exhausted, shell_getc can simply pop that string off
  2316.    the stack, restore the previous string, and continue with the character
  2317.    following the token whose expansion was originally pushed on the stack.)
  2318.  
  2319.    What we really want is a record of all tokens that have been expanded for
  2320.    aliases during the `current' call to read_token().  This does that, at the
  2321.    cost of being somewhat special-purpose (OK, OK vile and unclean). */
  2322.  
  2323. typedef struct _exp_saver {
  2324.       struct _exp_saver *next;
  2325.       char *saved_token;
  2326. } EXPANSION_SAVER;
  2327.  
  2328. EXPANSION_SAVER *expanded_token_stack = (EXPANSION_SAVER *)NULL;
  2329.  
  2330. static void
  2331. save_expansion (s)
  2332.      char *s;
  2333. {
  2334.   EXPANSION_SAVER *t;
  2335.  
  2336.   t = (EXPANSION_SAVER *) xmalloc (sizeof (EXPANSION_SAVER));
  2337.   t->saved_token = savestring (s);
  2338.   t->next = expanded_token_stack;
  2339.   expanded_token_stack = t;
  2340. }
  2341.  
  2342. /* Return 1 if TOKEN has already been expanded in the current `stack' of
  2343.    expansions.  If it has been expanded already, it will appear as the value
  2344.    of saved_token for some entry in the stack of expansions created for the
  2345.    current token being expanded. */
  2346. static int
  2347. token_has_been_expanded (token)
  2348.      char *token;
  2349. {
  2350.   register EXPANSION_SAVER *t = expanded_token_stack;
  2351.  
  2352.   while (t)
  2353.     {
  2354.       if (STREQ (token, t->saved_token))
  2355.     return (1);
  2356.       t = t->next;
  2357.     }
  2358.   return (0);
  2359. }
  2360.  
  2361. static void
  2362. free_expansion_stack ()
  2363. {
  2364.   register EXPANSION_SAVER *t = expanded_token_stack, *t1;
  2365.  
  2366.   while (t)
  2367.     {
  2368.       t1 = t->next;
  2369.       free (t->saved_token);
  2370.       free (t);
  2371.       t = t1;
  2372.     }
  2373.   expanded_token_stack = (EXPANSION_SAVER *)NULL;
  2374. }
  2375.  
  2376. #endif /* ALIAS */
  2377.  
  2378. /* Return a line of text, taken from wherever yylex () reads input.
  2379.    If there is no more input, then we return NULL.  If REMOVE_QUOTED_NEWLINE
  2380.    is non-zero, we remove unquoted \<newline> pairs.  This is used by
  2381.    read_secondary_line to read here documents. */
  2382. static char *
  2383. read_a_line (remove_quoted_newline)
  2384.      int remove_quoted_newline;
  2385. {
  2386.   static char *line_buffer = (char *)NULL;
  2387.   static int buffer_size = 0;
  2388.   int indx = 0, c, peekc, pass_next;
  2389.  
  2390.   pass_next = 0;
  2391.   while (1)
  2392.     {
  2393.       c = yy_getc ();
  2394.  
  2395.       /* Allow immediate exit if interrupted during input. */
  2396.       QUIT;
  2397.  
  2398.       if (c == 0)
  2399.     continue;
  2400.  
  2401.       /* If there is no more input, then we return NULL. */
  2402.       if (c == EOF)
  2403.     {
  2404.       if (indx == 0)
  2405.         return ((char *)NULL);
  2406.       c = '\n';
  2407.     }
  2408.  
  2409.       /* `+2' in case the final character in the buffer is a newline. */
  2410.       if (indx + 2 > buffer_size)
  2411.     if (!buffer_size)
  2412.       line_buffer = xmalloc (buffer_size = 400);
  2413.     else
  2414.       line_buffer = xrealloc (line_buffer, buffer_size += 400);
  2415.  
  2416.       /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
  2417.      here document with an unquoted delimiter.  In this case,
  2418.      the line will be expanded as if it were in double quotes.
  2419.      We allow a backslash to escape the next character, but we
  2420.      need to treat the backslash specially only if a backslash
  2421.      quoting a backslash-newline pair appears in the line. */
  2422.       if (pass_next)
  2423.         {
  2424.       line_buffer[indx++] = c;
  2425.       pass_next = 0;
  2426.         }
  2427.       else if (c == '\\' && remove_quoted_newline)
  2428.     {
  2429.       peekc = yy_getc ();
  2430.       if (peekc == '\n')
  2431.         continue;    /* Make the unquoted \<newline> pair disappear. */
  2432.       else
  2433.         {
  2434.           yy_ungetc (peekc);
  2435.           pass_next = 1;
  2436.           line_buffer[indx++] = c;        /* Preserve the backslash. */
  2437.         }
  2438.     }
  2439.       else
  2440.     line_buffer[indx++] = c;
  2441.  
  2442.       if (c == '\n')
  2443.     {
  2444.       line_buffer[indx] = '\0';
  2445.       return (line_buffer);
  2446.     }
  2447.     }
  2448. }
  2449.  
  2450. /* Return a line as in read_a_line (), but insure that the prompt is
  2451.    the secondary prompt.  This is used to read the lines of a here
  2452.    document.  REMOVE_QUOTED_NEWLINE is non-zero if we should remove
  2453.    newlines quoted with backslashes while reading the line.  It is
  2454.    non-zero unless the delimiter of the here document was quoted. */
  2455. char *
  2456. read_secondary_line (remove_quoted_newline)
  2457.      int remove_quoted_newline;
  2458. {
  2459.   prompt_string_pointer = &ps2_prompt;
  2460.   prompt_again ();
  2461.   return (read_a_line (remove_quoted_newline));
  2462. }
  2463.  
  2464.  
  2465. /* **************************************************************** */
  2466. /*                                    */
  2467. /*                YYLEX ()                */
  2468. /*                                    */
  2469. /* **************************************************************** */
  2470.  
  2471. /* Reserved words.  These are only recognized as the first word of a
  2472.    command. */
  2473. STRING_INT_ALIST word_token_alist[] = {
  2474.   { "if", IF },
  2475.   { "then", THEN },
  2476.   { "else", ELSE },
  2477.   { "elif", ELIF },
  2478.   { "fi", FI },
  2479.   { "case", CASE },
  2480.   { "esac", ESAC },
  2481.   { "for", FOR },
  2482. #if defined (SELECT_COMMAND)
  2483.   { "select", SELECT },
  2484. #endif
  2485.   { "while", WHILE },
  2486.   { "until", UNTIL },
  2487.   { "do", DO },
  2488.   { "done", DONE },
  2489.   { "in", IN },
  2490.   { "function", FUNCTION },
  2491.   { "{", '{' },
  2492.   { "}", '}' },
  2493.   { "!", BANG },
  2494.   { (char *)NULL, 0}
  2495. };
  2496.  
  2497. /* Return the next shell input character.  This always reads characters
  2498.    from shell_input_line; when that line is exhausted, it is time to
  2499.    read the next line.  This is called by read_token when the shell is
  2500.    processing normal command input. */
  2501. static int
  2502. shell_getc (remove_quoted_newline)
  2503.      int remove_quoted_newline;
  2504. {
  2505.   int c;
  2506.  
  2507.   QUIT;
  2508.  
  2509. #if defined (ALIAS)
  2510.   /* If shell_input_line[shell_input_line_index] == 0, but there is
  2511.      something on the pushed list of strings, then we don't want to go
  2512.      off and get another line.  We let the code down below handle it. */
  2513.  
  2514.   if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
  2515.                 (pushed_string_list == (STRING_SAVER *)NULL)))
  2516. #else /* !ALIAS */
  2517.   if (!shell_input_line || !shell_input_line[shell_input_line_index])
  2518. #endif /* !ALIAS */
  2519.     {
  2520.       register int i, l;
  2521.  
  2522.       restart_read_next_line:
  2523.  
  2524.       line_number++;
  2525.  
  2526.     restart_read:
  2527.  
  2528.       /* Allow immediate exit if interrupted during input. */
  2529.       QUIT;
  2530.  
  2531.       i = 0;
  2532.       shell_input_line_terminator = 0;
  2533.  
  2534. #if defined (JOB_CONTROL)
  2535.       /* This can cause a problem when reading a command as the result
  2536.      of a trap, when the trap is called from flush_child.  This call
  2537.      had better not cause jobs to disappear from the job table in
  2538.      that case, or we will have big trouble. */
  2539.       notify_and_cleanup ();
  2540. #else /* !JOB_CONTROL */
  2541.       cleanup_dead_jobs ();
  2542. #endif /* !JOB_CONTROL */
  2543.  
  2544. #if defined (READLINE)
  2545.       if (interactive && no_line_editing)
  2546. #else
  2547.       if (interactive)
  2548. #endif
  2549.     print_prompt ();
  2550.  
  2551.       if (bash_input.type == st_stream)
  2552.     clearerr (stdin);
  2553.  
  2554.       while (c = yy_getc ())
  2555.     {
  2556.       /* Allow immediate exit if interrupted during input. */
  2557.       QUIT;
  2558.  
  2559.       if (i + 2 > shell_input_line_size)
  2560.         shell_input_line =
  2561.           xrealloc (shell_input_line, shell_input_line_size += 256);
  2562.  
  2563.       if (c == EOF)
  2564.         {
  2565.           if (bash_input.type == st_stream)
  2566.         clearerr (stdin);
  2567.  
  2568.           if (!i)
  2569.         shell_input_line_terminator = EOF;
  2570.  
  2571.           shell_input_line[i] = '\0';
  2572.           break;
  2573.         }
  2574.  
  2575.       shell_input_line[i++] = c;
  2576.  
  2577.       if (c == '\n')
  2578.         {
  2579.           shell_input_line[--i] = '\0';
  2580.           current_command_line_count++;
  2581.           break;
  2582.         }
  2583.     }
  2584.       shell_input_line_index = 0;
  2585.       shell_input_line_len = i;        /* == strlen (shell_input_line) */
  2586.  
  2587. #if defined (HISTORY)
  2588.       if (interactive && shell_input_line && shell_input_line[0])
  2589.     {
  2590.       char *expansions;
  2591.  
  2592.       expansions = pre_process_line (shell_input_line, 1, 1);
  2593.  
  2594.       free (shell_input_line);
  2595.       shell_input_line = expansions;
  2596.       shell_input_line_len = shell_input_line ?
  2597.                  strlen (shell_input_line) :
  2598.                  0;
  2599.       if (!shell_input_line_len)
  2600.         current_command_line_count--;
  2601.  
  2602.       /* We have to force the xrealloc below because we don't know the
  2603.          true allocated size of shell_input_line anymore. */
  2604.       shell_input_line_size = shell_input_line_len;
  2605.     }
  2606. #endif /* HISTORY */
  2607.  
  2608.       if (shell_input_line)
  2609.     {
  2610.       /* Lines that signify the end of the shell's input should not be
  2611.          echoed. */
  2612.       if (echo_input_at_read && (shell_input_line[0] ||
  2613.                      shell_input_line_terminator != EOF))
  2614.         fprintf (stderr, "%s\n", shell_input_line);
  2615.     }
  2616.       else
  2617.     {
  2618.       shell_input_line_size = 0;
  2619.       prompt_string_pointer = ¤t_prompt_string;
  2620.       prompt_again ();
  2621.       goto restart_read;
  2622.     }
  2623.  
  2624.       /* Add the newline to the end of this string, iff the string does
  2625.      not already end in an EOF character.  */
  2626.       if (shell_input_line_terminator != EOF)
  2627.     {
  2628.       l = shell_input_line_len;    /* was a call to strlen */
  2629.  
  2630.       if (l + 3 > shell_input_line_size)
  2631.         shell_input_line = xrealloc (shell_input_line,
  2632.                     1 + (shell_input_line_size += 2));
  2633.  
  2634.       shell_input_line[l] = '\n';
  2635.       shell_input_line[l + 1] = '\0';
  2636.     }
  2637.     }
  2638.   
  2639.   c = shell_input_line[shell_input_line_index];
  2640.  
  2641.   if (c)
  2642.     shell_input_line_index++;
  2643.  
  2644.   if (c == '\\' && remove_quoted_newline &&
  2645.       shell_input_line[shell_input_line_index] == '\n')
  2646.     {
  2647.     prompt_again ();
  2648.     goto restart_read_next_line;
  2649.     }
  2650.  
  2651. #if defined (ALIAS)
  2652.   /* If C is NULL, we have reached the end of the current input string.  If
  2653.      pushed_string_list is non-empty, it's time to pop to the previous string
  2654.      because we have fully consumed the result of the last alias expansion.
  2655.      Do it transparently; just return the next character of the string popped
  2656.      to. */
  2657.   if (!c && (pushed_string_list != (STRING_SAVER *)NULL))
  2658.     {
  2659.       pop_string ();
  2660.       c = shell_input_line[shell_input_line_index];
  2661.       if (c)
  2662.     shell_input_line_index++;
  2663.     }
  2664. #endif /* ALIAS */
  2665.  
  2666.   if (!c && shell_input_line_terminator == EOF)
  2667.     {
  2668.       if (shell_input_line_index != 0)
  2669.     return ('\n');
  2670.       else
  2671.     return (EOF);
  2672.     }
  2673.  
  2674.   return (c);
  2675. }
  2676.  
  2677. /* Put C back into the input for the shell. */
  2678. static void
  2679. shell_ungetc (c)
  2680.      int c;
  2681. {
  2682.   if (shell_input_line && shell_input_line_index)
  2683.     shell_input_line[--shell_input_line_index] = c;
  2684. }
  2685.  
  2686. /* Discard input until CHARACTER is seen. */
  2687. static void
  2688. discard_until (character)
  2689.      int character;
  2690. {
  2691.   int c;
  2692.  
  2693.   while ((c = shell_getc (0)) != EOF && c != character)
  2694.     ;
  2695.  
  2696.   if (c != EOF)
  2697.     shell_ungetc (c);
  2698. }
  2699.  
  2700. /* Place to remember the token.  We try to keep the buffer
  2701.    at a reasonable size, but it can grow. */
  2702. static char *token = (char *)NULL;
  2703.  
  2704. /* Current size of the token buffer. */
  2705. static int token_buffer_size = 0;
  2706.  
  2707. void
  2708. execute_prompt_command (command)
  2709.      char *command;
  2710. {
  2711.   Function *temp_last, *temp_this;
  2712.   char *last_lastarg;
  2713.   int temp_exit_value, temp_eof_encountered;
  2714.  
  2715.   temp_last = last_shell_builtin;
  2716.   temp_this = this_shell_builtin;
  2717.   temp_exit_value = last_command_exit_value;
  2718.   temp_eof_encountered = eof_encountered;
  2719.   last_lastarg = get_string_value ("_");
  2720.   if (last_lastarg)
  2721.     last_lastarg = savestring (last_lastarg);
  2722.  
  2723.   parse_and_execute (savestring (command), "PROMPT_COMMAND", 0);
  2724.  
  2725.   last_shell_builtin = temp_last;
  2726.   this_shell_builtin = temp_this;
  2727.   last_command_exit_value = temp_exit_value;
  2728.   eof_encountered = temp_eof_encountered;
  2729.  
  2730.   bind_variable ("_", last_lastarg);
  2731.   FREE (last_lastarg);
  2732. }
  2733.  
  2734. /* Command to read_token () explaining what we want it to do. */
  2735. #define READ 0
  2736. #define RESET 1
  2737. #define prompt_is_ps1 \
  2738.       (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
  2739.  
  2740. /* Function for yyparse to call.  yylex keeps track of
  2741.    the last two tokens read, and calls read_token.  */
  2742.  
  2743. yylex ()
  2744. {
  2745.   if (interactive && (!current_token || current_token == '\n'))
  2746.     {
  2747.       /* Before we print a prompt, we might have to check mailboxes.
  2748.      We do this only if it is time to do so. Notice that only here
  2749.      is the mail alarm reset; nothing takes place in check_mail ()
  2750.      except the checking of mail.  Please don't change this. */
  2751.       if (prompt_is_ps1 && time_to_check_mail ())
  2752.     {
  2753.       check_mail ();
  2754.       reset_mail_timer ();
  2755.     }
  2756.  
  2757.       /* Avoid printing a prompt if we're not going to read anything, e.g.
  2758.      after resetting the parser with read_token (RESET). */
  2759.       if (token_to_read == 0 && interactive)
  2760.     prompt_again ();
  2761.     }
  2762.  
  2763.   token_before_that = last_read_token;
  2764.   last_read_token = current_token;
  2765.   current_token = read_token (READ);
  2766.   return (current_token);
  2767. }
  2768.  
  2769. /* Called from shell.c when Control-C is typed at top level.  Or
  2770.    by the error rule at top level. */
  2771. reset_parser ()
  2772. {
  2773.   read_token (RESET);
  2774. }
  2775.   
  2776. /* When non-zero, we have read the required tokens
  2777.    which allow ESAC to be the next one read. */
  2778. static int allow_esac_as_next = 0;
  2779.  
  2780. /* When non-zero, accept single '{' as a token itself. */
  2781. static int allow_open_brace = 0;
  2782.  
  2783. /* DELIMITERS is a stack of the nested delimiters that we have
  2784.    encountered so far. */
  2785. static char *delimiters = (char *)NULL;
  2786.  
  2787. /* Offset into the stack of delimiters. */
  2788. int delimiter_depth = 0;
  2789.  
  2790. /* How many slots are allocated to DELIMITERS. */
  2791. static int delimiter_space = 0;
  2792.  
  2793. void
  2794. gather_here_documents ()
  2795. {
  2796.   int r = 0;
  2797.   while (need_here_doc)
  2798.     {
  2799.       make_here_document (redir_stack[r++]);
  2800.       need_here_doc--;
  2801.     }
  2802. }
  2803.  
  2804. /* Macro for accessing the top delimiter on the stack.  Returns the
  2805.    delimiter or zero if none. */
  2806. #define current_delimiter() \
  2807.   (delimiter_depth ? delimiters[delimiter_depth - 1] : 0)
  2808.  
  2809. #define push_delimiter(character) \
  2810.   do \
  2811.     { \
  2812.       if (delimiter_depth + 2 > delimiter_space) \
  2813.     delimiters = xrealloc \
  2814.       (delimiters, (delimiter_space += 10) * sizeof (char)); \
  2815.       delimiters[delimiter_depth] = character; \
  2816.       delimiter_depth++; \
  2817.     } \
  2818.   while (0)
  2819.  
  2820. /* When non-zero, an open-brace used to create a group is awaiting a close
  2821.    brace partner. */
  2822. static int open_brace_awaiting_satisfaction = 0;
  2823.  
  2824. #define command_token_position(token) \
  2825.   (((token) == ASSIGNMENT_WORD) || \
  2826.    ((token) != SEMI_SEMI && reserved_word_acceptable(token)))
  2827.  
  2828. #define assignment_acceptable(token) command_token_position(token) && \
  2829.                     (in_case_pattern_list == 0)
  2830.  
  2831. /* Check to see if TOKEN is a reserved word and return the token
  2832.    value if it is. */
  2833. #define CHECK_FOR_RESERVED_WORD(tok) \
  2834.   do { \
  2835.     if (!dollar_present && !quoted && \
  2836.     reserved_word_acceptable (last_read_token)) \
  2837.       { \
  2838.     int i; \
  2839.     for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
  2840.       if (STREQ (tok, word_token_alist[i].word)) \
  2841.         { \
  2842.           if (in_case_pattern_list && (word_token_alist[i].token != ESAC)) \
  2843.         break; \
  2844. \
  2845.           if (word_token_alist[i].token == ESAC) \
  2846.         in_case_pattern_list = 0; \
  2847. \
  2848.           if (word_token_alist[i].token == '{') \
  2849.         open_brace_awaiting_satisfaction++; \
  2850. \
  2851.           return (word_token_alist[i].token); \
  2852.         } \
  2853.       } \
  2854.   } while (0)
  2855.  
  2856. /* Read the next token.  Command can be READ (normal operation) or 
  2857.    RESET (to normalize state). */
  2858. static int
  2859. read_token (command)
  2860.      int command;
  2861. {
  2862.   int character;        /* Current character. */
  2863.   int peek_char;        /* Temporary look-ahead character. */
  2864.   int result;            /* The thing to return. */
  2865.   WORD_DESC *the_word;        /* The value for YYLVAL when a WORD is read. */
  2866.  
  2867.   if (token_buffer_size < TOKEN_DEFAULT_GROW_SIZE)
  2868.     {
  2869.       FREE (token);
  2870.       token = xmalloc (token_buffer_size = TOKEN_DEFAULT_GROW_SIZE);
  2871.     }
  2872.  
  2873.   if (command == RESET)
  2874.     {
  2875.       delimiter_depth = 0;    /* No delimiters found so far. */
  2876.       open_brace_awaiting_satisfaction = 0;
  2877.       in_case_pattern_list = 0;
  2878.  
  2879. #if defined (ALIAS)
  2880.       if (pushed_string_list)
  2881.     {
  2882.       free_string_list ();
  2883.       pushed_string_list = (STRING_SAVER *)NULL;
  2884.     }
  2885.  
  2886.       if (expanded_token_stack)
  2887.     {
  2888.       free_expansion_stack ();
  2889.       expanded_token_stack = (EXPANSION_SAVER *)NULL;
  2890.     }
  2891.  
  2892.       expand_next_token = 0;
  2893. #endif /* ALIAS */
  2894.  
  2895.       if (shell_input_line)
  2896.     {
  2897.       free (shell_input_line);
  2898.       shell_input_line = (char *)NULL;
  2899.       shell_input_line_size = shell_input_line_index = 0;
  2900.     }
  2901.       last_read_token = '\n';
  2902.       token_to_read = '\n';
  2903.       return ('\n');
  2904.     }
  2905.  
  2906.   if (token_to_read)
  2907.     {
  2908.       int rt = token_to_read;
  2909.       token_to_read = 0;
  2910.       return (rt);
  2911.     }
  2912.  
  2913. #if defined (ALIAS)
  2914.   /* If we hit read_token () and there are no saved strings on the
  2915.      pushed_string_list, then we are no longer currently expanding a
  2916.      token.  This can't be done in pop_stream, because pop_stream
  2917.      may pop the stream before the current token has finished being
  2918.      completely expanded (consider what happens when we alias foo to foo,
  2919.      and then try to expand it). */
  2920.   if (!pushed_string_list && expanded_token_stack)
  2921.     {
  2922.       free_expansion_stack ();
  2923.       expanded_token_stack = (EXPANSION_SAVER *)NULL;
  2924.     }
  2925.  
  2926.   /* This is a place to jump back to once we have successfully expanded a
  2927.      token with an alias and pushed the string with push_string () */
  2928.  re_read_token:
  2929.  
  2930. #endif /* ALIAS */
  2931.  
  2932.   /* Read a single word from input.  Start by skipping blanks. */
  2933.   while ((character = shell_getc (1)) != EOF && whitespace (character));
  2934.  
  2935.   if (character == EOF)
  2936.     {
  2937.       EOF_Reached = 1;
  2938.       return (yacc_EOF);
  2939.     }
  2940.  
  2941.   if (character == '#' && (!interactive || interactive_comments))
  2942.     {
  2943.       /* A comment.  Discard until EOL or EOF, and then return a newline. */
  2944.       discard_until ('\n');
  2945.       shell_getc (0);
  2946.  
  2947.       /* If we're about to return an unquoted newline, we can go and collect
  2948.      the text of any pending here documents. */
  2949.       if (need_here_doc)
  2950.         gather_here_documents ();
  2951.  
  2952. #if defined (ALIAS)
  2953.       expand_next_token = 0;
  2954. #endif /* ALIAS */
  2955.  
  2956.       return ('\n');
  2957.     }
  2958.  
  2959.   if (character == '\n')
  2960.     {
  2961.       /* If we're about to return an unquoted newline, we can go and collect
  2962.      the text of any pending here document. */
  2963.       if (need_here_doc)
  2964.     gather_here_documents ();
  2965.  
  2966. #if defined (ALIAS)
  2967.       expand_next_token = 0;
  2968. #endif /* ALIAS */
  2969.  
  2970.       return (character);
  2971.     }
  2972.  
  2973.   if (member (character, "()<>;&|"))
  2974.     {
  2975. #if defined (ALIAS)
  2976.       /* Turn off alias tokenization iff this character sequence would
  2977.      not leave us ready to read a command. */
  2978.       if (character == '<' || character == '>')
  2979.     expand_next_token = 0;
  2980. #endif /* ALIAS */
  2981.  
  2982.       /* Please note that the shell does not allow whitespace to
  2983.      appear in between tokens which are character pairs, such as
  2984.      "<<" or ">>".  I believe this is the correct behaviour. */
  2985.       if (character == (peek_char = shell_getc (1)))
  2986.     {
  2987.       switch (character)
  2988.         {
  2989.           /* If '<' then we could be at "<<" or at "<<-".  We have to
  2990.          look ahead one more character. */
  2991.         case '<':
  2992.           peek_char = shell_getc (1);
  2993.           if (peek_char == '-')
  2994.         return (LESS_LESS_MINUS);
  2995.           else
  2996.         {
  2997.           shell_ungetc (peek_char);
  2998.           return (LESS_LESS);
  2999.         }
  3000.  
  3001.         case '>':
  3002.           return (GREATER_GREATER);
  3003.  
  3004.         case ';':
  3005.           in_case_pattern_list = 1;
  3006. #if defined (ALIAS)
  3007.           expand_next_token = 0;
  3008. #endif /* ALIAS */
  3009.           return (SEMI_SEMI);
  3010.  
  3011.         case '&':
  3012.           return (AND_AND);
  3013.  
  3014.         case '|':
  3015.           return (OR_OR);
  3016.         }
  3017.     }
  3018.       else
  3019.     {
  3020.       if (peek_char == '&')
  3021.         {
  3022.           switch (character)
  3023.         {
  3024.         case '<': return (LESS_AND);
  3025.         case '>': return (GREATER_AND);
  3026.         }
  3027.         }
  3028.       if (character == '<' && peek_char == '>')
  3029.         return (LESS_GREATER);
  3030.       if (character == '>' && peek_char == '|')
  3031.         return (GREATER_BAR);
  3032.       if (peek_char == '>' && character == '&')
  3033.         return (AND_GREATER);
  3034.     }
  3035.       shell_ungetc (peek_char);
  3036.  
  3037.       /* If we look like we are reading the start of a function
  3038.      definition, then let the reader know about it so that
  3039.      we will do the right thing with `{'. */
  3040.       if (character == ')' &&
  3041.       last_read_token == '(' && token_before_that == WORD)
  3042.     {
  3043.       allow_open_brace = 1;
  3044. #if defined (ALIAS)
  3045.       expand_next_token = 0;
  3046. #endif /* ALIAS */
  3047.     }
  3048.  
  3049.       if (in_case_pattern_list && (character == ')'))
  3050.     in_case_pattern_list = 0;
  3051.  
  3052. #if defined (PROCESS_SUBSTITUTION)
  3053.       /* Check for the constructs which introduce process substitution.
  3054.      Shells running in `posix mode' don't do process substitution. */
  3055.       if (posixly_correct ||
  3056.       (((character == '>' || character == '<') && peek_char == '(') == 0))
  3057. #endif /* PROCESS_SUBSTITUTION */
  3058.     return (character);
  3059.     }
  3060.  
  3061.   /* Hack <&- (close stdin) case. */
  3062.   if (character == '-')
  3063.     {
  3064.       switch (last_read_token)
  3065.     {
  3066.     case LESS_AND:
  3067.     case GREATER_AND:
  3068.       return (character);
  3069.     }
  3070.     }
  3071.   
  3072.   /* Okay, if we got this far, we have to read a word.  Read one,
  3073.      and then check it against the known ones. */
  3074.   {
  3075.     /* Index into the token that we are building. */
  3076.     int token_index = 0;
  3077.  
  3078.     /* ALL_DIGITS becomes zero when we see a non-digit. */
  3079.     int all_digits = digit (character);
  3080.  
  3081.     /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
  3082.     int dollar_present = 0;
  3083.  
  3084.     /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
  3085.     int quoted = 0;
  3086.  
  3087.     /* Non-zero means to ignore the value of the next character, and just
  3088.        to add it no matter what. */
  3089.     int pass_next_character = 0;
  3090.  
  3091.     /* Non-zero means parsing a dollar-paren construct.  It is the count of
  3092.        un-quoted closes we need to see. */
  3093.     int dollar_paren_level = 0;
  3094.  
  3095.     /* Non-zero means parsing a dollar-bracket construct ($[...]).  It is
  3096.        the count of un-quoted `]' characters we need to see. */
  3097.     int dollar_bracket_level = 0;
  3098.  
  3099.     /* Non-zero means parsing a `${' construct.  It is the count of
  3100.        un-quoted `}' we need to see. */
  3101.     int dollar_brace_level = 0;
  3102.  
  3103.     /* A level variable for parsing '${ ... }' constructs inside of double
  3104.        quotes. */
  3105.     int delimited_brace_level = 0;
  3106.  
  3107.     /* A boolean variable denoting whether or not we are currently parsing
  3108.        a double-quoted string embedded in a $( ) or ${ } construct. */
  3109.     int embedded_quoted_string = 0;
  3110.  
  3111.     /* Another level variable.  This one is for dollar_parens inside of
  3112.        double-quotes. */
  3113.     int delimited_paren_level = 0;
  3114.  
  3115.     /* The current delimiting character. */
  3116.     int cd;
  3117.  
  3118.     for (;;)
  3119.       {
  3120.     if (character == EOF)
  3121.       goto got_token;
  3122.  
  3123.     if (pass_next_character)
  3124.       {
  3125.         pass_next_character = 0;
  3126.         goto got_character;
  3127.       }
  3128.  
  3129.     cd = current_delimiter ();
  3130.  
  3131.     if (cd && character == '\\' && cd != '\'')
  3132.       {
  3133.         peek_char = shell_getc (0);
  3134.         if (peek_char != '\\')
  3135.           shell_ungetc (peek_char);
  3136.         else
  3137.           {
  3138.         token[token_index++] = character;
  3139.         goto got_character;
  3140.           }
  3141.       }
  3142.  
  3143.     /* Handle backslashes.  Quote lots of things when not inside of
  3144.        double-quotes, quote some things inside of double-quotes. */
  3145.        
  3146.     if (character == '\\' && (!delimiter_depth || cd != '\''))
  3147.       {
  3148.         peek_char = shell_getc (0);
  3149.  
  3150.         /* Backslash-newline is ignored in all cases excepting
  3151.            when quoted with single quotes. */
  3152.         if (peek_char == '\n')
  3153.           {
  3154.         character = '\n';
  3155.         goto next_character;
  3156.           }
  3157.         else
  3158.           {
  3159.         shell_ungetc (peek_char);
  3160.  
  3161.         /* If the next character is to be quoted, do it now. */
  3162.         if (!cd || cd == '`' ||
  3163.             (cd == '"' && member (peek_char, slashify_in_quotes)))
  3164.           {
  3165.             pass_next_character++;
  3166.             quoted = 1;
  3167.             goto got_character;
  3168.           }
  3169.           }
  3170.       }
  3171.  
  3172.     /* This is a hack, in its present form.  If a backquote substitution
  3173.        appears within double quotes, everything within the backquotes
  3174.        should be read as part of a single word.  Jesus.  Now I see why
  3175.        Korn introduced the $() form. */
  3176.     if (delimiter_depth && (cd == '"') && (character == '`'))
  3177.       {
  3178.         push_delimiter (character);
  3179.         goto got_character;
  3180.       }
  3181.  
  3182.     cd = current_delimiter ();        /* XXX - may not need */
  3183.     if (delimiter_depth)
  3184.       {
  3185.         if (character == cd)
  3186.           {
  3187.               /* If we see a double quote while parsing a double-quoted
  3188.           $( ) or ${ }, and we have not seen ) or }, respectively,
  3189.                  note that we are in the middle of reading an embedded
  3190.            quoted string. */
  3191.         if ((delimited_paren_level || delimited_brace_level) &&
  3192.             (character == '"'))
  3193.           {
  3194.             embedded_quoted_string = !embedded_quoted_string;
  3195.             goto got_character;
  3196.           }
  3197.         
  3198.         delimiter_depth--;
  3199.         goto got_character;
  3200.           }
  3201.       }
  3202.  
  3203.     if (cd != '\'')
  3204.       {
  3205. #if defined (PROCESS_SUBSTITUTION)
  3206.         if (character == '$' || character == '<' || character == '>')
  3207. #else
  3208.         if (character == '$')
  3209. #endif /* !PROCESS_SUBSTITUTION */
  3210.           {
  3211.               /* If we're in the middle of parsing a $( ) or ${ }
  3212.                  construct with an embedded quoted string, don't
  3213.                  bother looking at this character any further. */
  3214.               if (embedded_quoted_string)
  3215.                 goto got_character;
  3216.  
  3217.         peek_char = shell_getc (1);
  3218.         shell_ungetc (peek_char);
  3219.         if (peek_char == '(')
  3220.           {
  3221.             if (!delimiter_depth)
  3222.               dollar_paren_level++;
  3223.             else
  3224.               delimited_paren_level++;
  3225.  
  3226.             pass_next_character++;
  3227.             goto got_character;
  3228.           }
  3229.         else if (peek_char == '[' && character == '$')
  3230.           {
  3231.             if (!delimiter_depth)
  3232.               dollar_bracket_level++;
  3233.  
  3234.             pass_next_character++;
  3235.             goto got_character;
  3236.           }
  3237.         /* This handles ${...} constructs. */
  3238.         else if (peek_char == '{' && character == '$')
  3239.           {
  3240.             if (!delimiter_depth)
  3241.               dollar_brace_level++;
  3242.             else
  3243.               delimited_brace_level++;
  3244.  
  3245.             pass_next_character++;
  3246.             goto got_character;
  3247.           }
  3248.           }
  3249.  
  3250.         /* If we are parsing a $() or $[] construct, we need to balance
  3251.            parens and brackets inside the construct.  This whole function
  3252.            could use a rewrite. */
  3253.         if (character == '(' && !embedded_quoted_string)
  3254.           {
  3255.         if (delimiter_depth && delimited_paren_level)
  3256.           delimited_paren_level++;
  3257.  
  3258.         if (!delimiter_depth && dollar_paren_level)
  3259.           dollar_paren_level++;
  3260.           }
  3261.  
  3262.         if (character == '[')
  3263.           {
  3264.         if (!delimiter_depth && dollar_bracket_level)
  3265.           dollar_bracket_level++;
  3266.           }
  3267.  
  3268.         if (character == '{' && !embedded_quoted_string)
  3269.           {
  3270.               if (delimiter_depth && delimited_brace_level)
  3271.                 delimited_brace_level++;
  3272.  
  3273.               if (!delimiter_depth && dollar_brace_level)
  3274.                 dollar_brace_level++;
  3275.           }
  3276.  
  3277.         /* This code needs to take into account whether we are inside a
  3278.            case statement pattern list, and whether this paren is supposed
  3279.            to terminate it (hey, it could happen).  It's not as simple
  3280.            as just using in_case_pattern_list, because we're not parsing
  3281.            anything while we're reading a $( ) construct.  Maybe we
  3282.            should move that whole mess into the yacc parser. */
  3283.         if (character == ')' && !embedded_quoted_string)
  3284.           {
  3285.         if (delimiter_depth && delimited_paren_level)
  3286.           delimited_paren_level--;
  3287.  
  3288.         if (!delimiter_depth && dollar_paren_level)
  3289.           {
  3290.             dollar_paren_level--;
  3291.             goto got_character;
  3292.           }
  3293.           }
  3294.  
  3295.         if (character == ']')
  3296.           {
  3297.         if (!delimiter_depth && dollar_bracket_level)
  3298.           {
  3299.             dollar_bracket_level--;
  3300.             goto got_character;
  3301.           }
  3302.           }
  3303.  
  3304.         if (character == '}' && !embedded_quoted_string)
  3305.           {
  3306.         if (delimiter_depth && delimited_brace_level)
  3307.           delimited_brace_level--;
  3308.  
  3309.         if (!delimiter_depth && dollar_brace_level)
  3310.           {
  3311.             dollar_brace_level--;
  3312.             goto got_character;
  3313.           }
  3314.           }
  3315.       }
  3316.  
  3317.     if (!dollar_paren_level && !dollar_bracket_level &&
  3318.         !dollar_brace_level && !delimiter_depth &&
  3319.         member (character, " \t\n;&()|<>"))
  3320.       {
  3321.         shell_ungetc (character);
  3322.         goto got_token;
  3323.       }
  3324.     
  3325.     if (!delimiter_depth)
  3326.       {
  3327.         if (character == '"' || character == '`' || character == '\'')
  3328.           {
  3329.         push_delimiter (character);
  3330.  
  3331.         quoted = 1;
  3332.         goto got_character;
  3333.           }
  3334.       }
  3335.  
  3336.     if (all_digits)
  3337.       all_digits = digit (character);
  3338.     if (character == '$')
  3339.       dollar_present = 1;
  3340.  
  3341.       got_character:
  3342.  
  3343.     if (character == CTLESC || character == CTLNUL)
  3344.       token[token_index++] = CTLESC;
  3345.  
  3346.     token[token_index++] = character;
  3347.  
  3348.     if (token_index == (token_buffer_size - 1))
  3349.       {
  3350.         token_buffer_size += TOKEN_DEFAULT_GROW_SIZE;
  3351.         token = xrealloc (token, token_buffer_size);
  3352.       }
  3353.     next_character:
  3354.     if (character == '\n' && interactive && bash_input.type != st_string)
  3355.       prompt_again ();
  3356.  
  3357.     /* We want to remove quoted newlines (that is, a \<newline> pair)
  3358.        unless we are within single quotes or pass_next_character is
  3359.        set (the shell equivalent of literal-next). */
  3360.     character = shell_getc
  3361.       ((current_delimiter () != '\'') && (!pass_next_character));
  3362.       }
  3363.  
  3364.   got_token:
  3365.  
  3366.     token[token_index] = '\0';
  3367.     
  3368.     if ((delimiter_depth || dollar_paren_level || dollar_bracket_level) &&
  3369.     character == EOF)
  3370.       {
  3371.     char reporter = '\0';
  3372.  
  3373.     if (!delimiter_depth)
  3374.       {
  3375.         if (dollar_paren_level)
  3376.           reporter = ')';
  3377.         else if (dollar_bracket_level)
  3378.           reporter = ']';
  3379.       }
  3380.  
  3381.     if (!reporter)
  3382.       reporter = current_delimiter ();
  3383.  
  3384.     report_error ("unexpected EOF while looking for `%c'", reporter);
  3385.     return (-1);
  3386.       }
  3387.  
  3388.     if (all_digits)
  3389.       {
  3390.     /* Check to see what thing we should return.  If the last_read_token
  3391.        is a `<', or a `&', or the character which ended this token is
  3392.        a '>' or '<', then, and ONLY then, is this input token a NUMBER.
  3393.        Otherwise, it is just a word, and should be returned as such. */
  3394.  
  3395.     if (character == '<' || character == '>' ||
  3396.         last_read_token == LESS_AND || last_read_token == GREATER_AND)
  3397.       {
  3398.         yylval.number = atoi (token);
  3399.         return (NUMBER);
  3400.       }
  3401.       }
  3402.  
  3403.     /* Handle special case.  IN is recognized if the last token
  3404.        was WORD and the token before that was FOR or CASE. */
  3405.     if ((last_read_token == WORD) &&
  3406. #if defined (SELECT_COMMAND)
  3407.     ((token_before_that == FOR) || (token_before_that == CASE) || (token_before_that == SELECT)) &&
  3408. #else
  3409.     ((token_before_that == FOR) || (token_before_that == CASE)) &&
  3410. #endif
  3411.     (token[0] == 'i' && token[1] == 'n' && !token[2]))
  3412.       {
  3413.     if (token_before_that == CASE)
  3414.       {
  3415.         in_case_pattern_list = 1;
  3416.         allow_esac_as_next++;
  3417.       }
  3418.     return (IN);
  3419.       }
  3420.  
  3421.     /* Ditto for DO in the FOR case. */
  3422. #if defined (SELECT_COMMAND)
  3423.     if ((last_read_token == WORD) && ((token_before_that == FOR) || (token_before_that == SELECT)) &&
  3424. #else
  3425.     if ((last_read_token == WORD) && (token_before_that == FOR) &&
  3426. #endif
  3427.     (token[0] == 'd' && token[1] == 'o' && !token[2]))
  3428.       return (DO);
  3429.  
  3430.     /* Ditto for ESAC in the CASE case. 
  3431.        Specifically, this handles "case word in esac", which is a legal
  3432.        construct, certainly because someone will pass an empty arg to the
  3433.        case construct, and we don't want it to barf.  Of course, we should
  3434.        insist that the case construct has at least one pattern in it, but
  3435.        the designers disagree. */
  3436.     if (allow_esac_as_next)
  3437.       {
  3438.     allow_esac_as_next--;
  3439.     if (STREQ (token, "esac"))
  3440.       {
  3441.         in_case_pattern_list = 0;
  3442.         return (ESAC);
  3443.       }
  3444.       }
  3445.  
  3446.     /* Ditto for `{' in the FUNCTION case. */
  3447.     if (allow_open_brace)
  3448.       {
  3449.     allow_open_brace = 0;
  3450.     if (token[0] == '{' && !token[1])
  3451.       {
  3452.         open_brace_awaiting_satisfaction++;
  3453.         return ('{');
  3454.       }
  3455.       }
  3456.  
  3457.     if (posixly_correct)
  3458.       CHECK_FOR_RESERVED_WORD (token);
  3459.  
  3460. #if defined (ALIAS)
  3461.     /* OK, we have a token.  Let's try to alias expand it, if (and only if)
  3462.        it's eligible. 
  3463.  
  3464.        It is eligible for expansion if the shell is in interactive mode, and
  3465.        the token is unquoted and the last token read was a command
  3466.        separator (or expand_next_token is set), and we are currently
  3467.        processing an alias (pushed_string_list is non-empty) and this
  3468.        token is not the same as the current or any previously
  3469.        processed alias.
  3470.  
  3471.        Special cases that disqualify:
  3472.      In a pattern list in a case statement (in_case_pattern_list). */
  3473.     if (interactive_shell && !quoted && !in_case_pattern_list &&
  3474.     (expand_next_token || command_token_position (last_read_token)))
  3475.       {
  3476.     char *alias_expand_word (), *expanded;
  3477.  
  3478.     if (expanded_token_stack && token_has_been_expanded (token))
  3479.       goto no_expansion;
  3480.  
  3481.     expanded = alias_expand_word (token);
  3482.     if (expanded)
  3483.       {
  3484.         int len = strlen (expanded), expand_next;
  3485.  
  3486.         /* Erase the current token. */
  3487.         token_index = 0;
  3488.  
  3489.         expand_next = (expanded[len - 1] == ' ') ||
  3490.               (expanded[len - 1] == '\t');
  3491.  
  3492.         push_string (expanded, expand_next, token);
  3493.         goto re_read_token;
  3494.       }
  3495.     else
  3496.       /* This is an eligible token that does not have an expansion. */
  3497. no_expansion:
  3498.       expand_next_token = 0;
  3499.       }
  3500.     else
  3501.       {
  3502.     expand_next_token = 0;
  3503.       }
  3504. #endif /* ALIAS */
  3505.  
  3506.     if (!posixly_correct)
  3507.       CHECK_FOR_RESERVED_WORD (token);
  3508.  
  3509.     /* What if we are attempting to satisfy an open-brace grouper? */
  3510.     if (open_brace_awaiting_satisfaction && token[0] == '}' && !token[1])
  3511.       {
  3512.     open_brace_awaiting_satisfaction--;
  3513.     return ('}');
  3514.       }
  3515.  
  3516.     the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
  3517.     the_word->word = xmalloc (1 + token_index);
  3518.     strcpy (the_word->word, token);
  3519.     the_word->dollar_present = dollar_present;
  3520.     the_word->quoted = quoted;
  3521.     the_word->assignment = assignment (token);
  3522.  
  3523.     yylval.word = the_word;
  3524.     result = WORD;
  3525.  
  3526.     /* A word is an assignment if it appears at the beginning of a
  3527.        simple command, or after another assignment word.  This is
  3528.        context-dependent, so it cannot be handled in the grammar. */
  3529.     if (assignment_acceptable (last_read_token) && the_word->assignment)
  3530.       result = ASSIGNMENT_WORD;
  3531.  
  3532.     if (last_read_token == FUNCTION)
  3533.       allow_open_brace = 1;
  3534.   }
  3535.   return (result);
  3536. }
  3537.  
  3538. /* Return 1 if TOKEN is a token that after being read would allow
  3539.    a reserved word to be seen, else 0. */
  3540. static int
  3541. reserved_word_acceptable (token)
  3542.      int token;
  3543. {
  3544. #if 0
  3545.   if (member (token, "\n;()|&{") ||
  3546. #else
  3547.   if (token == '\n' || token == ';' || token == '(' || token == ')' ||
  3548.       token == '|' || token == '&' || token == '{' ||
  3549. #endif
  3550.       token == '}' ||            /* XXX */
  3551.       token == AND_AND ||
  3552.       token == BANG ||
  3553.       token == DO ||
  3554.       token == ELIF ||
  3555.       token == ELSE ||
  3556.       token == FI ||
  3557.       token == IF ||
  3558.       token == OR_OR ||
  3559.       token == SEMI_SEMI ||
  3560.       token == THEN ||
  3561.       token == UNTIL ||
  3562.       token == WHILE ||
  3563.       token == DONE ||        /* XXX these two are experimental */
  3564.       token == ESAC ||
  3565.       token == 0)
  3566.     return (1);
  3567.   else
  3568.     return (0);
  3569. }
  3570.  
  3571. /* Return the index of TOKEN in the alist of reserved words, or -1 if
  3572.    TOKEN is not a shell reserved word. */
  3573. int
  3574. find_reserved_word (token)
  3575.      char *token;
  3576. {
  3577.   int i;
  3578.   for (i = 0; word_token_alist[i].word != (char *)NULL; i++)
  3579.     if (STREQ (token, word_token_alist[i].word))
  3580.       return i;
  3581.   return -1;
  3582. }
  3583.  
  3584. #if defined (READLINE)
  3585. /* Called after each time readline is called.  This insures that whatever
  3586.    the new prompt string is gets propagated to readline's local prompt
  3587.    variable. */
  3588. static void
  3589. reset_readline_prompt ()
  3590. {
  3591.   if (prompt_string_pointer && *prompt_string_pointer)
  3592.     {
  3593.       char *temp_prompt;
  3594.  
  3595.       temp_prompt = decode_prompt_string (*prompt_string_pointer);
  3596.  
  3597.       if (!temp_prompt)
  3598.     temp_prompt = savestring ("");
  3599.  
  3600.       FREE (current_readline_prompt);
  3601.  
  3602.       current_readline_prompt = temp_prompt;
  3603.     }
  3604. }
  3605. #endif /* READLINE */
  3606.  
  3607. #if defined (HISTORY)
  3608. /* A list of tokens which can be followed by newlines, but not by
  3609.    semi-colons.  When concatenating multiple lines of history, the
  3610.    newline separator for such tokens is replaced with a space. */
  3611. static int no_semi_successors[] = {
  3612.   '\n', '{', '(', ')', ';', '&', '|',
  3613.   CASE, DO, ELSE, IF, IN, SEMI_SEMI, THEN, UNTIL, WHILE, AND_AND, OR_OR,
  3614.   0
  3615. };
  3616.  
  3617. /* If we are not within a delimited expression, try to be smart
  3618.    about which separators can be semi-colons and which must be
  3619.    newlines. */
  3620. char *
  3621. history_delimiting_chars ()
  3622. {
  3623.   if (!delimiter_depth)
  3624.     {
  3625.       register int i;
  3626.  
  3627.       for (i = 0; no_semi_successors[i]; i++)
  3628.     {
  3629.       if (token_before_that == no_semi_successors[i])
  3630.         return (" ");
  3631.     }
  3632.       return ("; ");
  3633.     }
  3634.   else
  3635.     return ("\n");
  3636. }
  3637. #endif /* HISTORY */
  3638.  
  3639. /* Issue a prompt, or prepare to issue a prompt when the next character
  3640.    is read. */
  3641. static void
  3642. prompt_again ()
  3643. {
  3644.   char *temp_prompt;
  3645.  
  3646.   if (!interactive)    /* XXX */
  3647.     return;
  3648.  
  3649.   ps1_prompt = get_string_value ("PS1");
  3650.   ps2_prompt = get_string_value ("PS2");
  3651.  
  3652.   if (!prompt_string_pointer)
  3653.     prompt_string_pointer = &ps1_prompt;
  3654.  
  3655.   if (*prompt_string_pointer)
  3656.     temp_prompt = decode_prompt_string (*prompt_string_pointer);
  3657.   else
  3658.     temp_prompt = savestring ("");
  3659.  
  3660.   current_prompt_string = *prompt_string_pointer;
  3661.   prompt_string_pointer = &ps2_prompt;
  3662.  
  3663. #if defined (READLINE)
  3664.   if (!no_line_editing)
  3665.     {
  3666.       FREE (current_readline_prompt);
  3667.       current_readline_prompt = temp_prompt;
  3668.     }
  3669.   else
  3670. #endif    /* READLINE */
  3671.     {
  3672.       FREE (current_decoded_prompt);
  3673.       current_decoded_prompt = temp_prompt;
  3674.     }
  3675. }
  3676.  
  3677. static void
  3678. print_prompt ()
  3679. {
  3680.   fprintf (stderr, "%s", current_decoded_prompt);
  3681.   fflush (stderr);
  3682. }
  3683.  
  3684. /* Return a string which will be printed as a prompt.  The string
  3685.    may contain special characters which are decoded as follows:
  3686.    
  3687.     \t    the time
  3688.     \d    the date
  3689.     \n    CRLF
  3690.     \s    the name of the shell
  3691.     \w    the current working directory
  3692.     \W    the last element of PWD
  3693.     \u    your username
  3694.     \h    the hostname
  3695.     \#    the command number of this command
  3696.     \!    the history number of this command
  3697.     \$    a $ or a # if you are root
  3698.     \<octal> character code in octal
  3699.     \\    a backslash
  3700. */
  3701. #define PROMPT_GROWTH 50
  3702. char *
  3703. decode_prompt_string (string)
  3704.      char *string;
  3705. {
  3706.   int result_size = PROMPT_GROWTH;
  3707.   int result_index = 0;
  3708.   char *result;
  3709.   int c;
  3710.   char *temp = (char *)NULL;
  3711.   WORD_LIST *list;
  3712.  
  3713. #if defined (PROMPT_STRING_DECODE)
  3714.  
  3715.   result = xmalloc (PROMPT_GROWTH);
  3716.   result[0] = 0;
  3717.  
  3718.   while (c = *string++)
  3719.     {
  3720.       if (posixly_correct && c == '!')
  3721.     {
  3722.       if (*string == '!')
  3723.         {
  3724.           temp = savestring ("!");
  3725.           goto add_string;
  3726.         }
  3727.       else
  3728.         {
  3729. #if !defined (HISTORY)
  3730.         temp = savestring ("1");
  3731. #else /* HISTORY */
  3732.         temp = itos (history_number ());
  3733. #endif /* HISTORY */
  3734.         string--;    /* add_string increments string again. */
  3735.         goto add_string;
  3736.         }
  3737.     } 
  3738.       if (c == '\\')
  3739.     {
  3740.       c = *string;
  3741.  
  3742.       switch (c)
  3743.         {
  3744.         case '0':
  3745.         case '1':
  3746.         case '2':
  3747.         case '3':
  3748.         case '4':
  3749.         case '5':
  3750.         case '6':
  3751.         case '7':
  3752.           {
  3753.         char octal_string[4];
  3754.         int n;
  3755.  
  3756.         strncpy (octal_string, string, 3);
  3757.         octal_string[3] = '\0';
  3758.  
  3759.         n = read_octal (octal_string);
  3760.  
  3761.         temp = savestring ("\\");
  3762.         if (n != -1)
  3763.           {
  3764.             string += 3;
  3765.             temp[0] = n;
  3766.           }
  3767.  
  3768.         c = 0;
  3769.         goto add_string;
  3770.           }
  3771.       
  3772.         case 't':
  3773.         case 'd':
  3774.           /* Make the current time/date into a string. */
  3775.           {
  3776.         time_t the_time = time (0);
  3777.         char *ttemp = ctime (&the_time);
  3778.         temp = savestring (ttemp);
  3779.  
  3780.         if (c == 't')
  3781.           {
  3782.             strcpy (temp, temp + 11);
  3783.             temp[8] = '\0';
  3784.           }
  3785.         else
  3786.           temp[10] = '\0';
  3787.  
  3788.         goto add_string;
  3789.           }
  3790.  
  3791.         case 'n':
  3792.           if (!no_line_editing)
  3793.         temp = savestring ("\r\n");
  3794.           else
  3795.         temp = savestring ("\n");
  3796.           goto add_string;
  3797.  
  3798.         case 's':
  3799.           {
  3800.         temp = base_pathname (shell_name);
  3801.         temp = savestring (temp);
  3802.         goto add_string;
  3803.           }
  3804.     
  3805.         case 'w':
  3806.         case 'W':
  3807.           {
  3808.         /* Use the value of PWD because it is much more effecient. */
  3809. #define EFFICIENT
  3810. #ifdef EFFICIENT
  3811.         char *polite_directory_format (), t_string[MAXPATHLEN];
  3812.  
  3813.         temp = get_string_value ("PWD");
  3814.  
  3815.         if (!temp)
  3816.           getwd (t_string);
  3817.         else
  3818.           strcpy (t_string, temp);
  3819. #else
  3820.         getwd (t_string);
  3821. #endif    /* EFFICIENT */
  3822.  
  3823.         if (c == 'W')
  3824.           {
  3825.             char *dir = (char *)strrchr (t_string, '/');
  3826.             if (dir && dir != t_string)
  3827.               strcpy (t_string, dir + 1);
  3828.             temp = savestring (t_string);
  3829.           }
  3830.         else
  3831.           temp = savestring (polite_directory_format (t_string));
  3832.         goto add_string;
  3833.           }
  3834.       
  3835.         case 'u':
  3836.           {
  3837.         temp = savestring (current_user.user_name);
  3838.         goto add_string;
  3839.           }
  3840.  
  3841.         case 'h':
  3842.           {
  3843.         char *t_string;
  3844.  
  3845.         temp = savestring (current_host_name);
  3846.         if (t_string = (char *)strchr (temp, '.'))
  3847.           *t_string = '\0';
  3848.         goto add_string;
  3849.           }
  3850.  
  3851.         case '#':
  3852.           {
  3853.         temp = itos (current_command_number);
  3854.         goto add_string;
  3855.           }
  3856.  
  3857.         case '!':
  3858.           {
  3859. #if !defined (HISTORY)
  3860.         temp = savestring ("1");
  3861. #else /* HISTORY */
  3862.         temp = itos (history_number ());
  3863. #endif /* HISTORY */
  3864.         goto add_string;
  3865.           }
  3866.  
  3867.         case '$':
  3868.           temp = savestring (geteuid () == 0 ? "#" : "$");
  3869.           goto add_string;
  3870.  
  3871.         case '[':
  3872.         case ']':
  3873.           temp = xmalloc(3);
  3874.           temp[0] = '\001';
  3875.           temp[1] = (c == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE;
  3876.           temp[2] = '\0';
  3877.           goto add_string;
  3878.  
  3879.         case '\\':
  3880.           temp = savestring ("\\");
  3881.           goto add_string;
  3882.  
  3883.         default:
  3884.           temp = savestring ("\\ ");
  3885.           temp[1] = c;
  3886.  
  3887.         add_string:
  3888.           if (c)
  3889.         string++;
  3890.           result =
  3891.         sub_append_string (temp, result, &result_index, &result_size);
  3892.           temp = (char *)NULL; /* Free ()'ed in sub_append_string (). */
  3893.           result[result_index] = '\0';
  3894.           break;
  3895.         }
  3896.     }
  3897.       else
  3898.     {
  3899.       while (3 + result_index > result_size)
  3900.         result = xrealloc (result, result_size += PROMPT_GROWTH);
  3901.  
  3902.       result[result_index++] = c;
  3903.       result[result_index] = '\0';
  3904.     }
  3905.     }
  3906. #else /* !PROMPT_STRING_DECODE */
  3907.   result = savestring (string);
  3908. #endif /* !PROMPT_STRING_DECODE */
  3909.  
  3910.   /* Perform variable and parameter expansion and command substitution on
  3911.      the prompt string. */
  3912.   list = expand_string (result, 1);
  3913.   free (result);
  3914.   result = string_list (list);
  3915.   dispose_words (list);
  3916.  
  3917.   return (result);
  3918. }
  3919.  
  3920. /* Report a syntax error, and restart the parser.  Call here for fatal
  3921.    errors. */
  3922. yyerror ()
  3923. {
  3924.   report_syntax_error ((char *)NULL);
  3925.   reset_parser ();
  3926. }
  3927.  
  3928. /* Report a syntax error with line numbers, etc.
  3929.    Call here for recoverable errors.  If you have a message to print,
  3930.    then place it in MESSAGE, otherwise pass NULL and this will figure
  3931.    out an appropriate message for you. */
  3932. static void
  3933. report_syntax_error (message)
  3934.      char *message;
  3935. {
  3936.   if (message)
  3937.     {
  3938.       if (!interactive)
  3939.     {
  3940.       char *name = bash_input.name ? bash_input.name : "stdin";
  3941.       report_error ("%s: line %d: `%s'", name, line_number, message);
  3942.     }
  3943.       else
  3944.     {
  3945.       if (EOF_Reached)
  3946.         EOF_Reached = 0;
  3947.       report_error ("%s", message);
  3948.     }
  3949.  
  3950.       last_command_exit_value = EX_USAGE;
  3951.       return;
  3952.     }
  3953.  
  3954.   if (shell_input_line && *shell_input_line)
  3955.     {
  3956.       char *t = shell_input_line;
  3957.       register int i = shell_input_line_index;
  3958.       int token_end = 0;
  3959.  
  3960.       if (!t[i] && i)
  3961.     i--;
  3962.  
  3963.       while (i && (t[i] == ' ' || t[i] == '\t' || t[i] == '\n'))
  3964.     i--;
  3965.  
  3966.       if (i)
  3967.     token_end = i + 1;
  3968.  
  3969.       while (i && !member (t[i], " \n\t;|&"))
  3970.     i--;
  3971.  
  3972.       while (i != token_end && member (t[i], " \t\n"))
  3973.     i++;
  3974.  
  3975.       if (token_end)
  3976.     {
  3977.       char *error_token;
  3978.       error_token = xmalloc (1 + (token_end - i));
  3979.       strncpy (error_token, t + i, token_end - i);
  3980.       error_token[token_end - i] = '\0';
  3981.  
  3982.       report_error ("syntax error near unexpected token `%s'", error_token);
  3983.       free (error_token);
  3984.     }
  3985.       else if ((i == 0) && (token_end == 0))    /* a 1-character token */
  3986.     {
  3987.       char etoken[2];
  3988.       etoken[0] = t[i];
  3989.       etoken[1] = '\0';
  3990.  
  3991.       report_error ("syntax error near unexpected token `%s'", etoken);
  3992.     }
  3993.  
  3994.       if (!interactive)
  3995.     {
  3996.       char *temp = savestring (shell_input_line);
  3997.       char *name = bash_input.name ? bash_input.name : "stdin";
  3998.       int l = strlen (temp);
  3999.  
  4000.       while (l && temp[l - 1] == '\n')
  4001.         temp[--l] = '\0';
  4002.  
  4003.       report_error ("%s: line %d: `%s'", name, line_number, temp);
  4004.       free (temp);
  4005.     }
  4006.     }
  4007.   else
  4008.     {
  4009.       char *name, *msg;
  4010.       if (!interactive)
  4011.     name = bash_input.name ? bash_input.name : "stdin";
  4012.       if (EOF_Reached)
  4013.     msg = "syntax error: unexpected end of file";
  4014.       else
  4015.     msg = "syntax error";
  4016.       if (!interactive)
  4017.     report_error ("%s: line %d: %s", name, line_number, msg);
  4018.       else
  4019.     {
  4020.       /* This file uses EOF_Reached only for error reporting
  4021.          when the shell is interactive.  Other mechanisms are 
  4022.          used to decide whether or not to exit. */
  4023.       EOF_Reached = 0;
  4024.       report_error (msg);
  4025.     }
  4026.     }
  4027.   last_command_exit_value = EX_USAGE;
  4028. }
  4029.  
  4030. /* ??? Needed function. ??? We have to be able to discard the constructs
  4031.    created during parsing.  In the case of error, we want to return
  4032.    allocated objects to the memory pool.  In the case of no error, we want
  4033.    to throw away the information about where the allocated objects live.
  4034.    (dispose_command () will actually free the command. */
  4035. discard_parser_constructs (error_p)
  4036.      int error_p;
  4037. {
  4038. }
  4039.    
  4040. /* Do that silly `type "bye" to exit' stuff.  You know, "ignoreeof". */
  4041.  
  4042. /* A flag denoting whether or not ignoreeof is set. */
  4043. int ignoreeof = 0;
  4044.  
  4045. /* The number of times that we have encountered an EOF character without
  4046.    another character intervening.  When this gets above the limit, the
  4047.    shell terminates. */
  4048. int eof_encountered = 0;
  4049.  
  4050. /* The limit for eof_encountered. */
  4051. int eof_encountered_limit = 10;
  4052.  
  4053. /* If we have EOF as the only input unit, this user wants to leave
  4054.    the shell.  If the shell is not interactive, then just leave.
  4055.    Otherwise, if ignoreeof is set, and we haven't done this the
  4056.    required number of times in a row, print a message. */
  4057. static void
  4058. handle_eof_input_unit ()
  4059. {
  4060.   if (interactive)
  4061.     {
  4062.       /* shell.c may use this to decide whether or not to write out the
  4063.      history, among other things.  We use it only for error reporting
  4064.      in this file. */
  4065.       if (EOF_Reached)
  4066.     EOF_Reached = 0;
  4067.  
  4068.       /* If the user wants to "ignore" eof, then let her do so, kind of. */
  4069.       if (ignoreeof)
  4070.     {
  4071.       if (eof_encountered < eof_encountered_limit)
  4072.         {
  4073.           fprintf (stderr, "Use \"%s\" to leave the shell.\n",
  4074.                login_shell ? "logout" : "exit");
  4075.           eof_encountered++;
  4076.           /* Reset the prompt string to be $PS1. */
  4077.           prompt_string_pointer = (char **)NULL;
  4078.           prompt_again ();
  4079.           last_read_token = current_token = '\n';
  4080.           return;
  4081.         } 
  4082.     }
  4083.  
  4084.       /* In this case EOF should exit the shell.  Do it now. */
  4085.       reset_parser ();
  4086.       exit_builtin ((WORD_LIST *)NULL);
  4087.     }
  4088.   else
  4089.     {
  4090.       /* We don't write history files, etc., for non-interactive shells. */
  4091.       EOF_Reached = 1;
  4092.     }
  4093. }
  4094.